From 839725e3c58f794ef6b78f497d7bb0a11ed44d2e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 14 Apr 2017 09:58:34 -0400 Subject: queuelogger: Automatically roll log file Signed-off-by: Kevin O'Connor --- klippy/queuelogger.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'klippy/queuelogger.py') 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 +# Copyright (C) 2016,2017 Kevin O'Connor # # 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() -- cgit v1.2.3-70-g09d2