From 55640c13151f302324c5ff72f27085d498a6ca2d Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Wed, 22 Oct 2014 18:27:59 +0100 Subject: [PATCH] Updated cookbook entry to replace shutil.chown with os.chown. --- Doc/howto/logging-cookbook.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 07b04f9c39..47cf0f44a5 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`, -- 2.50.1