Custom logging handler that cleans files on startup
This commit is contained in:
parent
891fd18f0e
commit
e8123a6ab1
3 changed files with 22 additions and 2 deletions
4
src/octoprint/logging/__init__.py
Normal file
4
src/octoprint/logging/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# coding=utf-8
|
||||
from __future__ import absolute_import
|
||||
|
||||
from . import handlers
|
||||
16
src/octoprint/logging/handlers.py
Normal file
16
src/octoprint/logging/handlers.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# coding=utf-8
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging.handlers
|
||||
import os
|
||||
|
||||
class CleaningTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
logging.handlers.TimedRotatingFileHandler.__init__(self, *args, **kwargs)
|
||||
|
||||
# clean up old files on handler start
|
||||
if self.backupCount > 0:
|
||||
for s in self.getFilesToDelete():
|
||||
os.remove(s)
|
||||
|
||||
|
|
@ -574,11 +574,11 @@ class Server(object):
|
|||
"stream": "ext://sys.stdout"
|
||||
},
|
||||
"file": {
|
||||
"class": "logging.handlers.TimedRotatingFileHandler",
|
||||
"class": "octoprint.logging.handlers.CleaningTimedRotatingFileHandler",
|
||||
"level": "DEBUG",
|
||||
"formatter": "simple",
|
||||
"when": "D",
|
||||
"backupCount": "1",
|
||||
"backupCount": 7,
|
||||
"filename": os.path.join(settings().getBaseFolder("logs"), "octoprint.log")
|
||||
},
|
||||
"serialFile": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue