From 220079e64ba984c17e596768f8ff92a51c1ec048 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 6 Oct 2022 05:38:34 +0200 Subject: [PATCH] Some more logging fixes in linspectord.py. --- bin/linspector | 4 ++-- linspector/core/linspectord.py | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bin/linspector b/bin/linspector index 6423b4f..332bd8c 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.20.* will become the first # stable version. -__version__ = '0.19.35.dev1' +__version__ = '0.19.36.dev1' __author__ = 'Johannes Findeisen ' @@ -166,7 +166,7 @@ def main(): if args.daemon: try: from linspector.core.linspectord import Linspectord - linspectord = Linspectord(configuration, environment, linspector) + linspectord = Linspectord(configuration, environment, linspector, log) # do handling of restart, start and stop commands but for now "start" is enough... ;) if args.kill: log('info', '[linspector] stopping daemon.') diff --git a/linspector/core/linspectord.py b/linspector/core/linspectord.py index 608a1eb..0ca6e54 100644 --- a/linspector/core/linspectord.py +++ b/linspector/core/linspectord.py @@ -9,20 +9,18 @@ import signal import sys import time -from linspector.core.helpers import log - # TODO: there is a bug when stopping the daemon. the pid_file is not being deleted. NEEDS A FIX! class Linspectord: - - def __init__(self, configuration, environment, linspector): + def __init__(self, configuration, environment, linspector, log): self.__configuration = configuration self.__environment = environment self.__linspector = linspector + self.__log = log try: self.__pid_file = configuration.get_option('linspector', 'pid_file') except Exception as err: - log('critical', __name__, str('daemonize error (no pid_file set): {0}'.format(err))) + log('critical', 'daemonize error (no pid_file set): {0}'.str(format(err))) def daemonize(self): # daemonize the class using the UNIX double fork mechanism. @@ -34,7 +32,7 @@ class Linspectord: # exit first parent. sys.exit(0) except OSError as err: - log('critical', __name__, str('fork #1 failed: {0}'.format(err))) + self.__log('critical', 'fork #1 failed: {0}'.str(format(err))) sys.exit(1) # decouple from parent environment. @@ -49,7 +47,7 @@ class Linspectord: # Exit from second parent. sys.exit(0) except OSError as err: - log('critical', __name__, str('fork #2 failed: {0}'.format(err))) + self.__log('critical', 'fork #2 failed: {0}'.str(format(err))) sys.exit(1) # redirect standard file descriptors. @@ -75,7 +73,7 @@ class Linspectord: def start(self): # start the daemon. check for a pidfile to see if the daemon already runs before. - log('info', __name__, 'starting daemon using pid_file: ' + self.__pid_file) + self.__log('info', 'starting daemon using pid_file: ' + str(self.__pid_file)) try: with open(self.__pid_file, 'r') as pf: pid = int(pf.read().strip()) @@ -84,7 +82,7 @@ class Linspectord: if pid: message = 'pid_file {0} already exist. daemon already running?' - log('critical', __name__, str(message.format(self.__pid_file))) + self.__log('critical', str(message.format(self.__pid_file))) sys.exit(1) # start the daemon. @@ -93,7 +91,7 @@ class Linspectord: def stop(self): # stop the daemon. - log('info', __name__, 'stopping daemon using pid_file: ' + self.__pid_file) + self.__log('info', 'stopping daemon using pid_file: ' + str(self.__pid_file)) # get the pid from the pid file. try: with open(self.__pid_file, 'r') as pf: @@ -103,7 +101,7 @@ class Linspectord: if not pid: message = 'pid_file {0} does not exist. daemon not running?' - log('error', __name__, str(message.format(self.__pid_file))) + self.__log('error', str(message.format(self.__pid_file))) return # not an error in a restart # try killing the daemon process. @@ -117,12 +115,12 @@ class Linspectord: if os.path.exists(self.__pid_file): os.remove(self.__pid_file) else: - log('critical', __name__, str(err.args)) + self.__log('critical', str(err.args)) sys.exit(1) def restart(self): # restart the daemon. - log('info', __name__, 'restarting daemon using pid_file: ' + self.__pid_file) + self.__log('info', 'restarting daemon using pid_file: ' + str(self.__pid_file)) self.stop() self.start()