diff options
author | Julien Cristau <julien.cristau@logilab.fr> | 2013-01-09 15:09:49 +0100 |
---|---|---|
committer | Julien Cristau <julien.cristau@logilab.fr> | 2013-01-09 15:09:49 +0100 |
commit | eea5dbb8992a20769eb3d73b78e035e20451102d (patch) | |
tree | f9cdeb7ea563f02b9b55d479f70371b07221b228 /logging_ext.py | |
parent | dbf8429a76013f48fbfa365c1b8f53b4e68acf1d (diff) | |
download | logilab-common-eea5dbb8992a20769eb3d73b78e035e20451102d.tar.gz |
logging: use WatchedFileHandler instead of FileHandler if available
This prevents logging to an old or deleted file after log rotation.
WatchedFileHandler is usable on Unix starting with Python 2.6.
Closes #115775.
Diffstat (limited to 'logging_ext.py')
-rw-r--r-- | logging_ext.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/logging_ext.py b/logging_ext.py index e4d2490..54cc48f 100644 --- a/logging_ext.py +++ b/logging_ext.py @@ -112,7 +112,11 @@ def get_handler(debug=False, syslog=False, logfile=None, rotation_parameters=Non else: try: if rotation_parameters is None: - handler = logging.FileHandler(logfile) + if os.name == 'posix' and sys.version_info >= (2, 6): + from logging.handlers import WatchedFileHandler + handler = WatchedFileHandler(logfile) + else: + handler = logging.FileHandler(logfile) else: from logging.handlers import TimedRotatingFileHandler handler = TimedRotatingFileHandler( |