From 70236fbac43c26edd6dae9b7f6adc15900832718 Mon Sep 17 00:00:00 2001 From: Italo Cunha Date: Tue, 17 Nov 2020 15:50:06 -0600 Subject: [PATCH] Allow setting log history size BIRD-LG currently keeps log files indefinitely. This patch allows setting the number of days logs should be kept for by adding a `LOG_NUM_DAYS` parameter in the configuration files. This change is backwards compatible: Running the updated code with old configuration files will keep logs indefinitely as before; new deployments based on the example configuration will keep logs indefinitely. --- lg.cfg | 2 ++ lg.py | 2 +- lgproxy.cfg | 2 ++ lgproxy.py | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lg.cfg b/lg.cfg index 4d120ea..505cda2 100644 --- a/lg.cfg +++ b/lg.cfg @@ -2,6 +2,8 @@ WEBSITE_TITLE="Bird-LG / Looking Glass" DEBUG = False LOG_FILE="/var/log/lg.log" LOG_LEVEL="WARNING" +# Keep log history indefinitely by default. +LOG_NUM_DAYS=0 DOMAIN = "tetaneutral.net" diff --git a/lg.py b/lg.py index 59cf17e..c811b25 100644 --- a/lg.py +++ b/lg.py @@ -48,7 +48,7 @@ app.config.from_pyfile(args.config_file) app.secret_key = app.config["SESSION_KEY"] app.debug = app.config["DEBUG"] -file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight") +file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight", backupCount=app.config.get("LOG_NUM_DAYS", 0)) file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper())) app.logger.addHandler(file_handler) diff --git a/lgproxy.cfg b/lgproxy.cfg index e4b08f8..0daded1 100644 --- a/lgproxy.cfg +++ b/lgproxy.cfg @@ -3,6 +3,8 @@ DEBUG=False LOG_FILE="/var/log/lg-proxy/lg-proxy.log" LOG_LEVEL="WARNING" +# Keep log history indefinitely by default. +LOG_NUM_DAYS=0 BIND_IP = "0.0.0.0" BIND_PORT = 5000 diff --git a/lgproxy.py b/lgproxy.py index 89b6a9a..0d0ad2d 100644 --- a/lgproxy.py +++ b/lgproxy.py @@ -41,7 +41,7 @@ app = Flask(__name__) app.debug = app.config["DEBUG"] app.config.from_pyfile(args.config_file) -file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight") +file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight", backupCount=app.config.get("LOG_NUM_DAYS", 0)) app.logger.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper())) app.logger.addHandler(file_handler)