Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the default log filename? #92

Open
AritraBasuPol opened this issue Dec 27, 2023 · 5 comments
Open

How to change the default log filename? #92

AritraBasuPol opened this issue Dec 27, 2023 · 5 comments

Comments

@AritraBasuPol
Copy link

Is there an argument parser so that the default logfile, "tricolour.log", can be chosen by an user?
Tricolour crashes if multiple users on a machine is executing tricolour from the same path. This is because different users do not have write permission on a file created by another user, even if they belong to the same group.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Singularity meerkat.simg:/data/mgps> tricolour
Unexpected error. Dropping you into pdb for a post-mortem.
Traceback (most recent call last):
File "/usr/local/bin/tricolour", line 11, in
load_entry_point('tricolour==0.1.8', 'console_scripts', 'tricolour')()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2854, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2451, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/local/lib/python3.8/dist-packages/tricolour-0.1.8-py3.8.egg/tricolour/apps/tricolour/app.py", line 80, in
log = create_logger()
File "/usr/local/lib/python3.8/dist-packages/tricolour-0.1.8-py3.8.egg/tricolour/apps/tricolour/app.py", line 65, in create_logger
filehandler = logging.FileHandler("tricolour.log")
File "/usr/lib/python3.8/logging/init.py", line 1147, in init
StreamHandler.init(self, self.open())
File "/usr/lib/python3.8/logging/_init.py", line 1176, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/data/mgps/tricolour.log'

@bennahugo
Copy link
Collaborator

bennahugo commented Dec 28, 2023 via email

@AritraBasuPol
Copy link
Author

Thanks Ben Hugo, Yes, adding timestamp would work perfectly. This is indeed what our strategy was expected to be, if a simple argument could have been parser.

For this, is it sufficient to change the follwoing, in app.py

def create_logger():
""" Create a console logger """
log = logging.getLogger("tricolour")
log.setLevel(logging.DEBUG)
filehandler = logging.FileHandler("tricolour.log")

to something like:

def create_logger():
""" Create a console logger """
fileAppend = subprocess.getoutput(('date +%b%d_%Y_%T'))
log = logging.getLogger("tricolour")
log.setLevel(logging.DEBUG)
filehandler = logging.FileHandler("tricolour_%s.log" %fileAppend)

Will making this change be sufficient, or do we have to change this elsewhere?
Also, will any new updated version be available anytime soon with this implemented?

@bennahugo
Copy link
Collaborator

bennahugo commented Dec 29, 2023 via email

@AritraBasuPol
Copy link
Author

Thanks. We will implement the patch locally and look forward to the updated version.

Best wishes,
Aritra.

bennahugo added a commit that referenced this issue Mar 28, 2024
- Make logfile path configurable
- Timestamp log
- Gracefully bail if logfile cannot be written
@bennahugo
Copy link
Collaborator

Upcoming release should make this configurable - see commit 3aff237

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

No branches or pull requests

2 participants