queuelogger: Automatically roll log file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
8920479f85
commit
839725e3c5
|
@ -26,9 +26,6 @@ Host user interaction
|
||||||
|
|
||||||
* Improve logging:
|
* 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
|
* Possibly collate and report the statistics messages in the log in a
|
||||||
more friendly way.
|
more friendly way.
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# Code to implement asynchronous logging from a background thread
|
# 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.
|
# 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 to forward all messages through a queue to a background thread
|
||||||
class QueueHandler(logging.Handler):
|
class QueueHandler(logging.Handler):
|
||||||
|
@ -38,8 +38,8 @@ class QueueListener(object):
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
|
|
||||||
def setup_bg_logging(filename, debuglevel):
|
def setup_bg_logging(filename, debuglevel):
|
||||||
logoutput = open(filename, 'wb')
|
handler = logging.handlers.TimedRotatingFileHandler(
|
||||||
handler = logging.StreamHandler(logoutput)
|
filename, when='midnight', backupCount=5)
|
||||||
ql = QueueListener(handler)
|
ql = QueueListener(handler)
|
||||||
qh = QueueHandler(ql.queue)
|
qh = QueueHandler(ql.queue)
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
|
|
Loading…
Reference in New Issue