From 4ae153f3beb237c0eb451e30730d3dac41c788f4 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 11 Oct 2022 01:14:24 +0200 Subject: [PATCH] Added process name and thread ID to logging. --- bin/linspector | 2 +- etc/linspector.conf | 4 ++-- linspector/core/helpers.py | 28 ++++++++++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bin/linspector b/bin/linspector index 15d4187..e3e1a3d 100755 --- a/bin/linspector +++ b/bin/linspector @@ -37,7 +37,7 @@ logger = logging.getLogger('linspector') # i currently only increase the 3rd number because the goal is that 0.19.* will become the first # stable version. -__version__ = '0.19.51.dev1' +__version__ = '0.19.52.dev1' __author__ = 'Johannes Findeisen ' diff --git a/etc/linspector.conf b/etc/linspector.conf index 13f2a93..12cd86f 100644 --- a/etc/linspector.conf +++ b/etc/linspector.conf @@ -11,7 +11,7 @@ log_file_count = 10 ; log file size in megabytes as int. the default is 10000000 bytes (10MiB) set in the code if not configured here. log_file_size = 5 ; 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. +; only be used when log_file_size is not set. if this value is not set too the default in the code will be used. log_file_size_bytes = 100000 pid_file = /var/run/user/1000/linspector.pid ; plugins separated by ','. no whitespaces allowed! not case sensitive. @@ -43,7 +43,7 @@ max_threads = 2048 ; i recommend to set this to your number of CPU cores available when running on a dedicated Linspector host. but if the ; system is running other services you should lower this value when you have too high CPU load. if you have enough ; resources this value really can be higher then your available CPU cores. -max_processes = 48 +max_processes = 12 ; if timezone is not set, UTC is used by default. timezone = CET ; this is for scheduling jobs to not run all at the same time. this should be set to the lowest interval you use. it diff --git a/linspector/core/helpers.py b/linspector/core/helpers.py index f881a3a..d335d64 100644 --- a/linspector/core/helpers.py +++ b/linspector/core/helpers.py @@ -12,25 +12,33 @@ def log(level, msg): # only use inspect when log level NOTSET or DEBUG is enabled. if logger.isEnabledFor(0) or logger.isEnabledFor(10): import inspect + import multiprocessing + import threading + current_process = multiprocessing.current_process() from_stack = inspect.stack()[1] function_name = from_stack.function line_number = str(from_stack.lineno) module_name = inspect.getmodule(from_stack[0]).__name__ if level == 'critical': - logger.critical('[' + module_name + ']:[' + function_name + ']:[' + line_number + '] ' + - str(msg)) + logger.critical('[' + str(current_process.name) + ']:[' + str(threading.get_ident()) + + ']:[' + str(threading.get_native_id()) + '] [' + module_name + ']:[' + + function_name + ']:[' + line_number + '] ' + str(msg)) if level == 'error': - logger.error('[' + module_name + ']:[' + function_name + ']:[' + line_number + '] ' + - str(msg)) + logger.error('[' + str(current_process.name) + ']:[' + str(threading.get_ident()) + + ']:[' + str(threading.get_native_id()) + '] [' + module_name + ']:[' + + function_name + ']:[' + line_number + '] ' + str(msg)) elif level == 'warning': - logger.warning('[' + module_name + ']:[' + function_name + ']:[' + line_number + '] ' + - str(msg)) + logger.warning('[' + str(current_process.name) + ']:[' + str(threading.get_ident()) + + ']:[' + str(threading.get_native_id()) + '] [' + module_name + ']:[' + + function_name + ']:[' + line_number + '] ' + str(msg)) elif level == 'info': - logger.info('[' + module_name + ']:[' + function_name + ']:[' + line_number + '] ' + - str(msg)) + logger.info('[' + str(current_process.name) + ']:[' + str(threading.get_ident()) + + ']:[' + str(threading.get_native_id()) + '] [' + module_name + ']:[' + + function_name + ']:[' + line_number + '] ' + str(msg)) elif level == 'debug': - logger.debug('[' + module_name + ']:[' + function_name + ']:[' + line_number + '] ' + - str(msg)) + logger.debug('[' + str(current_process.name) + ']:[' + str(threading.get_ident()) + + ']:[' + str(threading.get_native_id()) + '] [' + module_name + ']:[' + + function_name + ']:[' + line_number + '] ' + str(msg)) else: if level == 'critical': logger.critical(str(msg))