Added log_file_size_bytes to configuration. It can be used when log_file_size is not set.

This commit is contained in:
Johannes Findeisen 2022-10-04 23:23:36 +02:00
commit 60d4cd9dd8
2 changed files with 14 additions and 8 deletions

View file

@ -34,7 +34,7 @@ from linspector.core.monitors import Monitors
# i currently only increase the 3rd number because the goal is that 0.19 will become the first # i currently only increase the 3rd number because the goal is that 0.19 will become the first
# stable version. # stable version.
__version__ = '0.19.28.dev1' __version__ = '0.19.29.dev1'
__author__ = 'Johannes Findeisen <you@hanez.org>' __author__ = 'Johannes Findeisen <you@hanez.org>'
logger = logging.getLogger('linspector') logger = logging.getLogger('linspector')
@ -103,22 +103,25 @@ def main():
logging.Formatter('[%(asctime)s]:[%(levelname)s]:[%(name)s]:%(message)s') logging.Formatter('[%(asctime)s]:[%(levelname)s]:[%(name)s]:%(message)s')
if configuration.get_option('linspector', 'log_file_size'): if configuration.get_option('linspector', 'log_file_size'):
log_file_size_mb = float(configuration.get_option('linspector', 'log_file_size')) log_file_size_mb = int(configuration.get_option('linspector', 'log_file_size'))
b = 1000000 b = 1000000
log_file_size_bytes = log_file_size_mb * b log_file_size_bytes = int(log_file_size_mb * b)
elif configuration.get_option('linspector', 'log_file_size_bytes'):
log_file_size_bytes = int(configuration.get_option('linspector',
'log_file_size_bytes'))
else: else:
# default log file size is 10MB # default log file size is 10MB
log_file_size_bytes = 10485760 log_file_size_bytes = 10485760
if configuration.get_option('linspector', 'log_file_count'): if configuration.get_option('linspector', 'log_file_count'):
log_file_count = configuration.get_option('linspector', 'log_file_count') log_file_count = int(configuration.get_option('linspector', 'log_file_count'))
else: else:
# default log file count is 1. # default log file count is 1.
log_file_count = 1 log_file_count = 1
log_file_handler = logging.handlers.RotatingFileHandler(log_file, log_file_handler = logging.handlers.RotatingFileHandler(log_file,
maxBytes=int(log_file_size_bytes), maxBytes=log_file_size_bytes,
backupCount=int(log_file_count)) backupCount=log_file_count)
log_file_handler.setFormatter(log_file_formatter) log_file_handler.setFormatter(log_file_formatter)
logger.addHandler(log_file_handler) logger.addHandler(log_file_handler)

View file

@ -7,8 +7,11 @@ log_level= debug
log_file = ~/code/linspector/linspector/log/linspector.log log_file = ~/code/linspector/linspector/log/linspector.log
; number of log files to be kept. ; number of log files to be kept.
log_file_count = 50 log_file_count = 50
; log file size in megabytes as int or float. ; log file size in megabytes as int.
log_file_size = 1.00 log_file_size = 1
; log file size in bytes as int. you can set to bytes if you want to set a value lower then 1 megabyte. but it will
; only be used when log_file_size is not set.
log_file_size_bytes = 10485760
pid_file = /var/run/user/1000/linspector.pid pid_file = /var/run/user/1000/linspector.pid
; plugins separated by ','. no whitespaces allowed. not case sensitive. ; plugins separated by ','. no whitespaces allowed. not case sensitive.
plugins = Lish,HTTPServer plugins = Lish,HTTPServer