diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2014-10-22 17:27:59 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2014-10-22 17:27:59 (GMT) |
commit | 55640c13151f302324c5ff72f27085d498a6ca2d (patch) | |
tree | 7d6fc249d3451e6d50c672812cb0b52eb475eade | |
parent | 9e4a9339e159e03bcbcf154a4adba0761f9c36a8 (diff) | |
download | cpython-55640c13151f302324c5ff72f27085d498a6ca2d.zip cpython-55640c13151f302324c5ff72f27085d498a6ca2d.tar.gz cpython-55640c13151f302324c5ff72f27085d498a6ca2d.tar.bz2 |
Updated cookbook entry to replace shutil.chown with os.chown.
-rw-r--r-- | Doc/howto/logging-cookbook.rst | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 07b04f9..47cf0f4 100644 --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -846,15 +846,20 @@ Customizing handlers with :func:`dictConfig` There are times when you want to customize logging handlers in particular ways, and if you use :func:`dictConfig` you may be able to do this without subclassing. As an example, consider that you may want to set the ownership of a -log file. On POSIX, this is easily done using :func:`shutil.chown`, but the file +log file. On POSIX, this is easily done using :func:`os.chown`, but the file handlers in the stdlib don't offer built-in support. You can customize handler creation using a plain function such as:: def owned_file_handler(filename, mode='a', encoding=None, owner=None): if owner: + import os, pwd, grp + # convert user and group names to uid and gid + uid = pwd.getpwnam(owner[0]).pw_uid + gid = grp.getgrnam(owner[1]).gr_gid + owner = (uid, gid) if not os.path.exists(filename): open(filename, 'a').close() - shutil.chown(filename, *owner) + os.chown(filename, *owner) return logging.FileHandler(filename, mode, encoding) You can then specify, in a logging configuration passed to :func:`dictConfig`, |