Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@

# 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
log_file_path = os.path.join( tempfile.gettempdir(), 'buskill.log' )

# Fix for global logging in /tmp/buskill.log
# Changed it from a global log to user cache log
buskill = packages.buskill.BusKill()
log_file_path = os.path.join(buskill.CACHE_DIR, 'buskill.log')

logging.basicConfig(
filename = log_file_path,
Expand Down
15 changes: 14 additions & 1 deletion src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def __init__(self):
self.SIMULATE_HOTPLUG_REMOVAL = False

self.EXECUTED_AS_SCRIPT = None
self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename
# Fallback for script execution where logger handlers are not yet initialized
self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename if logger.root.handlers else None
self.EXE_PATH = None
self.EXE_DIR = None
self.EXE_FILE = None
Expand Down Expand Up @@ -407,6 +408,18 @@ def __init__(self):

# create a data dir in some safe place where we have write access
self.setupDataDir()

# CACHE_DIR is initialized inside setupDataDir().
# When running BusKill directly from source, logger handlers
# may not yet be configured, so initialize the fallback
# logfile path only after setupDataDir() has completed.
if self.LOG_FILE_PATH is None:
self.LOG_FILE_PATH = os.path.join(self.CACHE_DIR, 'buskill.log')
logging.basicConfig(
filename=self.LOG_FILE_PATH,
level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s'
)

# path to buskill's config file
self.CONF_FILE = os.path.join( self.DATA_DIR, "config.ini" )
Expand Down
Loading