diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-04-14 09:58:34 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-04-14 09:58:34 -0400 |
commit | 839725e3c58f794ef6b78f497d7bb0a11ed44d2e (patch) | |
tree | f326c616c5ed1f75a2c94e17f516b24d44236817 | |
parent | 8920479f857712d92a6d083f89b91d4830d2436f (diff) | |
download | kutter-839725e3c58f794ef6b78f497d7bb0a11ed44d2e.tar.gz kutter-839725e3c58f794ef6b78f497d7bb0a11ed44d2e.tar.xz kutter-839725e3c58f794ef6b78f497d7bb0a11ed44d2e.zip |
queuelogger: Automatically roll log file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | docs/Todo.md | 3 | ||||
-rw-r--r-- | klippy/queuelogger.py | 8 |
2 files changed, 4 insertions, 7 deletions
diff --git a/docs/Todo.md b/docs/Todo.md index 672a4c2c..b0bc69a4 100644 --- a/docs/Todo.md +++ b/docs/Todo.md @@ -26,9 +26,6 @@ Host user interaction * Improve logging: - * Automatically roll Klippy log files. The default log file should - have the current date in the log file name. - * Possibly collate and report the statistics messages in the log in a more friendly way. diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py index 8494c6a8..38a3d423 100644 --- a/klippy/queuelogger.py +++ b/klippy/queuelogger.py @@ -1,9 +1,9 @@ # Code to implement asynchronous logging from a background thread # -# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net> +# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. -import logging, threading, Queue +import logging, logging.handlers, threading, Queue # Class to forward all messages through a queue to a background thread class QueueHandler(logging.Handler): @@ -38,8 +38,8 @@ class QueueListener(object): self.thread.join() def setup_bg_logging(filename, debuglevel): - logoutput = open(filename, 'wb') - handler = logging.StreamHandler(logoutput) + handler = logging.handlers.TimedRotatingFileHandler( + filename, when='midnight', backupCount=5) ql = QueueListener(handler) qh = QueueHandler(ql.queue) root = logging.getLogger() |