1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-24 07:44:43 +01:00

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.
This commit is contained in:
Italo Cunha 2020-11-17 15:50:06 -06:00 committed by zorun
parent 3d90c14bfa
commit 30add2e41b
4 changed files with 6 additions and 2 deletions

2
lg.cfg
View file

@ -2,6 +2,8 @@ WEBSITE_TITLE="Bird-LG / Looking Glass"
DEBUG = False DEBUG = False
LOG_FILE="/var/log/lg.log" LOG_FILE="/var/log/lg.log"
LOG_LEVEL="WARNING" LOG_LEVEL="WARNING"
# Keep log history indefinitely by default.
LOG_NUM_DAYS=0
DOMAIN = "tetaneutral.net" DOMAIN = "tetaneutral.net"

2
lg.py
View file

@ -47,7 +47,7 @@ app.config.from_pyfile(args.config_file)
app.secret_key = app.config["SESSION_KEY"] app.secret_key = app.config["SESSION_KEY"]
app.debug = app.config["DEBUG"] 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())) file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)

View file

@ -3,6 +3,8 @@ DEBUG=False
LOG_FILE="/var/log/lg-proxy/lg-proxy.log" LOG_FILE="/var/log/lg-proxy/lg-proxy.log"
LOG_LEVEL="WARNING" LOG_LEVEL="WARNING"
# Keep log history indefinitely by default.
LOG_NUM_DAYS=0
BIND_IP = "0.0.0.0" BIND_IP = "0.0.0.0"
BIND_PORT = 5000 BIND_PORT = 5000

View file

@ -41,7 +41,7 @@ app = Flask(__name__)
app.debug = app.config["DEBUG"] app.debug = app.config["DEBUG"]
app.config.from_pyfile(args.config_file) 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.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)