From 5d7c6efb6a12a4c87325287829067a6b8f413ef0 Mon Sep 17 00:00:00 2001 From: Raihan93-coder Date: Fri, 29 May 2026 15:34:11 +0530 Subject: [PATCH 1/5] Implimented persistent logging in CLI --- src/buskill_cli.py | 7 ++++++ src/main.py | 37 +++++++++++++++++++++----------- src/packages/buskill/__init__.py | 6 +++++- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/buskill_cli.py b/src/buskill_cli.py index 8a5c3efda..757061a40 100755 --- a/src/buskill_cli.py +++ b/src/buskill_cli.py @@ -111,6 +111,13 @@ def BusKillCLI( buskill_object ): action="store_true" ) + # These arguments do not play a major role other than showing its use case + # Can initialise the persistent debug from here using the stack-overflow reference https://stackoverflow.com/questions/6255050/python-thinking-of-a-module-and-its-variables-as-a-singleton-clean-approach + parser.add_argument( + "-d","--debug", + help="To initiate persistent log" + ) + # process command-line arguments args = parser.parse_args() diff --git a/src/main.py b/src/main.py index c8dfa6858..befbc0d28 100755 --- a/src/main.py +++ b/src/main.py @@ -68,17 +68,32 @@ def start_logging(file_name): # TODO: disable logging by default; enable it with an argument # TODO: be able to override the path to the log file with an env var or argument value; make these just the defaults + + # instantiate the buskill object EARLY + # Moved to top so that DATA_DIR path can be found from the buskill class + global bk + bk = packages.buskill.BusKill() - try: - log_file_path = os.path.join( tempfile.gettempdir() , 'buskill.log' ) - start_logging(log_file_path) - except PermissionError: - # adding a fallback log to avoid PermissionError - # This creates a new file that appends the timestamp to the log file - timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') - log_file_path = os.path.join( tempfile.gettempdir() , f'buskill.{timestamp}.log') - + # sys argument fr persistent log + # Can be moved to buskill_cli using reference from https://stackoverflow.com/questions/6255050/python-thinking-of-a-module-and-its-variables-as-a-singleton-clean-approach + persistent_debug = '--debug' in sys.argv + + if persistent_debug: + # Initialising new location for the log file + log_file_path = os.path.join( bk.DATA_DIR , 'buskill.log') start_logging(log_file_path) + else: + try: + log_file_path = os.path.join( tempfile.gettempdir() , 'buskill.log' ) + start_logging(log_file_path) + except PermissionError: + # adding a fallback log to avoid PermissionError + # This creates a new file that appends the timestamp to the log file + timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') + log_file_path = os.path.join( tempfile.gettempdir() , f'buskill.{timestamp}.log') + start_logging(log_file_path) + + bk.LOG_FILE_PATH = log_file_path msg = "===============================================================================" print( msg ); logging.info( msg ) @@ -153,10 +168,6 @@ def start_logging(file_name): msg = "buskill version " +str(BUSKILL_VERSION) print( msg ); logging.info( msg ) - # instantiate the buskill object - global bk - bk = packages.buskill.BusKill() - ############# # LAUNCH UI # ############# diff --git a/src/packages/buskill/__init__.py b/src/packages/buskill/__init__.py index a39aaafe4..1e7a3f003 100644 --- a/src/packages/buskill/__init__.py +++ b/src/packages/buskill/__init__.py @@ -224,7 +224,11 @@ def __init__(self): self.SIMULATE_HOTPLUG_REMOVAL = False self.EXECUTED_AS_SCRIPT = None - self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename + + # BusKill class was always initialised after finding the log file path Therefore in the new setup we are initialising it before the log file path is found + # This will prevent it from out of index error + self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else Non + self.EXE_PATH = None self.EXE_DIR = None self.EXE_FILE = None From 5689b0532dbae299837085115174fe80ee33a747 Mon Sep 17 00:00:00 2001 From: Raihan93-coder Date: Fri, 29 May 2026 16:04:57 +0530 Subject: [PATCH 2/5] Typo error --- src/packages/buskill/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/buskill/__init__.py b/src/packages/buskill/__init__.py index 1e7a3f003..73ece082c 100644 --- a/src/packages/buskill/__init__.py +++ b/src/packages/buskill/__init__.py @@ -227,7 +227,7 @@ def __init__(self): # BusKill class was always initialised after finding the log file path Therefore in the new setup we are initialising it before the log file path is found # This will prevent it from out of index error - self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else Non + self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else None self.EXE_PATH = None self.EXE_DIR = None From 7fe6602c0ede45a1a6cef44db15fa9822bf2ac62 Mon Sep 17 00:00:00 2001 From: Raihan93-coder Date: Tue, 2 Jun 2026 09:01:42 +0530 Subject: [PATCH 3/5] Implimented config file based persistent logging --- src/buskill_cli.py | 7 ------- src/main.py | 6 +----- src/packages/buskill/__init__.py | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/buskill_cli.py b/src/buskill_cli.py index 757061a40..8a5c3efda 100755 --- a/src/buskill_cli.py +++ b/src/buskill_cli.py @@ -111,13 +111,6 @@ def BusKillCLI( buskill_object ): action="store_true" ) - # These arguments do not play a major role other than showing its use case - # Can initialise the persistent debug from here using the stack-overflow reference https://stackoverflow.com/questions/6255050/python-thinking-of-a-module-and-its-variables-as-a-singleton-clean-approach - parser.add_argument( - "-d","--debug", - help="To initiate persistent log" - ) - # process command-line arguments args = parser.parse_args() diff --git a/src/main.py b/src/main.py index befbc0d28..1e0d9ac04 100755 --- a/src/main.py +++ b/src/main.py @@ -74,11 +74,7 @@ def start_logging(file_name): global bk bk = packages.buskill.BusKill() - # sys argument fr persistent log - # Can be moved to buskill_cli using reference from https://stackoverflow.com/questions/6255050/python-thinking-of-a-module-and-its-variables-as-a-singleton-clean-approach - persistent_debug = '--debug' in sys.argv - - if persistent_debug: + if bk.persistent_log: # Initialising new location for the log file log_file_path = os.path.join( bk.DATA_DIR , 'buskill.log') start_logging(log_file_path) diff --git a/src/packages/buskill/__init__.py b/src/packages/buskill/__init__.py index 73ece082c..52f95a815 100644 --- a/src/packages/buskill/__init__.py +++ b/src/packages/buskill/__init__.py @@ -228,6 +228,8 @@ def __init__(self): # BusKill class was always initialised after finding the log file path Therefore in the new setup we are initialising it before the log file path is found # This will prevent it from out of index error self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else None + # Default value as False, because if no one updates the config.ini file then reverting back to old file path + self.persistent_log = False self.EXE_PATH = None self.EXE_DIR = None @@ -433,6 +435,8 @@ def __init__(self): msg = "DEBUG: CONF_FILE:|" +str(self.CONF_FILE)+ "|\n" print( msg ); logger.debug( msg ) + # running the config option only after the implimentation of the config file + self.getConfigOption() # handle conditions where this version was already upgraded by a newer # version or if this is a version that upgraded an older version @@ -445,6 +449,20 @@ def __init__(self): # * https://bugs.python.org/issue34034 # * https://docs.python.org/3/library/pickle.html#object.__reduce__ # * https://docs.python.org/3/library/pickle.html#object.__getstate__ + + + # Old config file reading option only exist after the toggling between the arm and disarm functionality + # Created a new function to get config option for persistent log file + def getConfigOption(self): + self.config = configparser.ConfigParser() + self.config.read( self.CONF_FILE ) + + if self.config.has_option('buskill', 'persistent_log'): + self.persistent_log = self.config.getboolean( + 'buskill', + 'persistent_log' + ) + def __getstate__(self): state = self.__dict__.copy() From f415cb906f868d6f4dc4429d078532efa0e90b7d Mon Sep 17 00:00:00 2001 From: Raihan93-coder Date: Wed, 3 Jun 2026 07:11:59 +0530 Subject: [PATCH 4/5] Implimented consistent naming convention --- src/main.py | 2 +- src/packages/buskill/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 1e0d9ac04..2af040219 100755 --- a/src/main.py +++ b/src/main.py @@ -74,7 +74,7 @@ def start_logging(file_name): global bk bk = packages.buskill.BusKill() - if bk.persistent_log: + if bk.PERSISTENT_LOG: # Initialising new location for the log file log_file_path = os.path.join( bk.DATA_DIR , 'buskill.log') start_logging(log_file_path) diff --git a/src/packages/buskill/__init__.py b/src/packages/buskill/__init__.py index 52f95a815..830472b21 100644 --- a/src/packages/buskill/__init__.py +++ b/src/packages/buskill/__init__.py @@ -229,7 +229,7 @@ def __init__(self): # This will prevent it from out of index error self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else None # Default value as False, because if no one updates the config.ini file then reverting back to old file path - self.persistent_log = False + self.PERSISTENT_LOG = False self.EXE_PATH = None self.EXE_DIR = None @@ -458,7 +458,7 @@ def getConfigOption(self): self.config.read( self.CONF_FILE ) if self.config.has_option('buskill', 'persistent_log'): - self.persistent_log = self.config.getboolean( + self.PERSISTENT_LOG = self.config.getboolean( 'buskill', 'persistent_log' ) From c5252b309ca90883b79832273c665f7405fb2dc1 Mon Sep 17 00:00:00 2001 From: Raihan93-coder Date: Thu, 4 Jun 2026 09:06:31 +0530 Subject: [PATCH 5/5] Decision of choosing log dir moved to a variable --- src/main.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main.py b/src/main.py index 8b047345e..253e77f7f 100755 --- a/src/main.py +++ b/src/main.py @@ -74,20 +74,18 @@ def start_logging(file_name): global bk bk = packages.buskill.BusKill() - if bk.PERSISTENT_LOG: - # Initialising new location for the log file - log_file_path = os.path.join( bk.DATA_DIR , 'buskill.log') + # Decision whether to write to DATA_DIR or TEMP file + log_dir = bk.DATA_DIR if bk.PERSISTENT_LOG else tempfile.gettempdir() + + try: + log_file_path = os.path.join( log_dir , 'buskill.log' ) + start_logging(log_file_path) + except PermissionError: + # adding a fallback log to avoid PermissionError + # This creates a new file that appends the timestamp to the log file + timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') + log_file_path = os.path.join( log_dir , f'buskill.{timestamp}.log') start_logging(log_file_path) - else: - try: - log_file_path = os.path.join( tempfile.gettempdir() , 'buskill.log' ) - start_logging(log_file_path) - except PermissionError: - # adding a fallback log to avoid PermissionError - # This creates a new file that appends the timestamp to the log file - timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') - log_file_path = os.path.join( tempfile.gettempdir() , f'buskill.{timestamp}.log') - start_logging(log_file_path) bk.LOG_FILE_PATH = log_file_path