summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/logs/utils.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2015-06-19 17:50:10 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-06-22 15:52:37 -0300
commit8793f3ef6862ddd5a01008b2e12d1f8d910fd261 (patch)
tree24d46dd1c211fad8d45576ea1f363806050ce1f7 /src/leap/bitmask/logs/utils.py
parent239a0ec845d53b7a0a1af5c27b5eea956ab6459a (diff)
[feat] add log rotation feature
Rotate bitmask.log file on each start.
Diffstat (limited to 'src/leap/bitmask/logs/utils.py')
-rw-r--r--src/leap/bitmask/logs/utils.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/leap/bitmask/logs/utils.py b/src/leap/bitmask/logs/utils.py
index 413f6a75..d3aa322b 100644
--- a/src/leap/bitmask/logs/utils.py
+++ b/src/leap/bitmask/logs/utils.py
@@ -36,7 +36,7 @@ from logbook.more import ColorizedStderrHandler
BITMASK_LOG_FILE = os.path.join(get_path_prefix(), "leap", 'bitmask.log')
-def get_logger():
+def get_logger(perform_rollover=False):
"""
Push to the app stack the needed handlers and return a Logger object.
@@ -56,9 +56,13 @@ def get_logger():
level=level, filter=silencer.filter)
zmq_handler.push_application()
- file_handler = logbook.FileHandler(BITMASK_LOG_FILE,
- format_string=LOG_FORMAT, bubble=True,
- filter=silencer.filter)
+ file_handler = logbook.RotatingFileHandler(
+ BITMASK_LOG_FILE, format_string=LOG_FORMAT, bubble=True,
+ filter=silencer.filter, max_size=sys.maxint)
+
+ if perform_rollover:
+ file_handler.perform_rollover()
+
file_handler.push_application()
# don't use simple stream, go for colored log handler instead