Skip to content

Add persistent log - #121

Merged
maltfield merged 6 commits into
BusKill:devfrom
Raihan93-coder:add-persistent-log
Jun 7, 2026
Merged

Add persistent log#121
maltfield merged 6 commits into
BusKill:devfrom
Raihan93-coder:add-persistent-log

Conversation

@Raihan93-coder

Copy link
Copy Markdown

Persistent Logging

I have implemented the persistent logging feature in CLI, I have not integrated it in GUI, The idea is simple if the user have given a debug flag in the terminal then instead of the program writing the log to /tmp/buskill.log, it will write to DATA_DIR/buskill.log.
The CLI work around of getting the bool is a bit clumsy but I have also added a reference link from stack-overflow, If you wanted I can implement that instead of the present implementation style

Problems faced

There was quite a lot of challenges That I have faced, And some was quite hilarious as I was trying to solve the problem which I had already solved earlier but still was trying to wrap my brain around it

  • Logging was initialized before BusKill() instantiation The biggest issue was that logging initialization happens very early in main.py, before the BusKill object is instantiated. This created an architectural issue because, DATA_DIR only becomes available after BusKill() initialization, but the logging path must be decided before logging initialization, This prevented directly using bk.DATA_DIR during initial log setup.

  • logger.root.handlers[0] indexing issue; Inside BusKill.init, the following line caused an indexing error if logging had not already been initialized self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename This meant:

    • The class depended on logging already existing
    • but persistent logging required information from the class before logging setup

    This circular dependency was the main source of the implementation difficulty.
    This was Issue I was taking earlier 😭

  • Initially I introduced self.persistent_log = False inside BusKill.init. Then inside buskill_cli.py buskill_object.persistent_log = args.debug However, the value appeared unchanged in main.py. After debugging with id() checks, I discovered; different BusKill() instances were being referenced logging initialization occurred before CLI argument processing, So the --debug argument was being applied too late to influence the initial log path.

Conclusion

I checked the working across root and regular user and it is working as intended
The path to DATA_DIR in my case is the <user_dir>/.local/share/.buskill/buskill.log across both root and regular user
If any problem or implementation logic flaw exist please let me know and I will also give you the reference link to the stack-overflow solution that I was referring down below
stack_overflow_solution


Sincerely,
Raihan 🤓

@github-actions

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

@maltfield

maltfield commented Jun 1, 2026

Copy link
Copy Markdown
Member

Hi @Raihan93-coder thanks for the PR :)

Sorry if this wasn't clear, but the reason that #34 was blocked by #16 was that this was supposed to be setup in a config file option, not as an argument (eg --debug).

Issue #16 added a config file (CONF_FILE) in DATA_DIR/config.ini. In it, there's a section [buskill] where we add config options. We should add a new boolean config to this file called persist_log. If that boolean value is True, then the log file should be written to the DATA_DIR. Else it should be the default, in the temp dir.

Can you please update this PR to use a config option in config.ini -- instead of an argument?

@maltfield

Copy link
Copy Markdown
Member

See also the docs for getboolean() in ConfigParser:

And how we implement this in our current setting buskill_trigger

# set the default trigger to what's defined in the config file
self.config = configparser.ConfigParser()
self.config.read( self.CONF_FILE )
if self.config.has_option('buskill', 'buskill_trigger'):
trigger = self.config.get('buskill', 'buskill_trigger')
else:
trigger = 'lock-screen'
self.set_trigger( trigger )

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

@Raihan93-coder

Copy link
Copy Markdown
Author

I have made the changes as you suggested
I have created a new function that uses config parser, as the parser in the toggle function will only be executed after the state of the buskill app is changed

The present implementation works for cases like

  • user updated the config file and added the line persistent_log = True
  • user updated the config file and added the line persistent_log = False
  • user didn't update the config file

I have checked all these cases and it is working perfectly as intended

Comment thread src/packages/buskill/__init__.py Outdated
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

Comment thread src/main.py Outdated
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

@maltfield

maltfield commented Jun 7, 2026

Copy link
Copy Markdown
Member

in my testing, I discovered a bug

user@buskill:~/sandbox/Raihan93-coder/buskill-app$ sudo ~/kivy_appdir/opt/python3.12/bin/python3.12 src/main.py 
usb1.__version__:|3.1.0|
DEBUG: EXECUTED_AS_SCRIPT:|True|
DEBUG: EXE_PATH:|/home/user/sandbox/Raihan93-coder/buskill-app/src/main.py|
DEBUG: EXE_DIR:|/home/user/sandbox/Raihan93-coder/buskill-app/src|
DEBUG: EXE_FILE:|main.py|
DEBUG: APP_DIR:|/home/user/sandbox/Raihan93-coder/buskill-app|
DEBUG: APPS_DIR:|/home/user/sandbox/Raihan93-coder|
DEBUG: SRC_DIR:|/home/user/sandbox/Raihan93-coder/buskill-app/src|
DEBUG: os.environ['PATH']:|/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/sandbox/Raihan93-coder/buskill-app/src:/home/user/sandbox/Raihan93-coder/buskill-app|

DEBUG: Unable to write to '/root/.local/share'; skipping.
	[Errno 2] No such file or directory: '/root/.local/share/tmpnfjk1mr0'

I don't think this is related to your changes. I guess it happens when the .local dir doesn't yet exist for a user.

# and fall-back on the default $HOME/.local/share
data_dirs.append( os.path.join( os.path.expanduser('~'), '.local', 'share' ) )
# first try to create our data dir in the same dir that holds the dir
# where the buskill app was installed (and where future updates will be
# installed). This may be the BusKill USB drive itself.
data_dirs.append( self.APPS_DIR )
# Fall-back to the dir in which the executable is located
data_dirs.append( self.APP_DIR )
# finally, try the users's $HOME dir
data_dirs.append( os.path.join( os.path.expanduser('~') ) )
# iterate though our list of potential data dirs and pick the first one
# that we can actually write to
for data_dir in data_dirs:
# skip any empty data_dir
if data_dir == '' or data_dir == None:
continue
try:
testfile = tempfile.TemporaryFile( dir=data_dir )
testfile.close()
except Exception as e:
# we were unable to write to this data_dir; try the next one
msg = "DEBUG: Unable to write to '" +data_dir+ "'; skipping."
msg += "\n\t" +str(e)+ "\n"
print( msg ); logger.debug( msg )
continue

In another ticket, we should probably add logic that attempts to create the path to the DATA_DIR recursively (eg mkdir -p), if needed

@maltfield
maltfield merged commit 9c8263e into BusKill:dev Jun 7, 2026
1 check passed
@Raihan93-coder
Raihan93-coder deleted the add-persistent-log branch June 8, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants