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

Reworked logging to catch all logs and prints and be prettier #1250

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

mrvisscher
Copy link
Collaborator

@mrvisscher mrvisscher commented Mar 7, 2024

Rework of the logging module making it log everything, from prints made by other modules to the StdOut and StdErr calls from C code.

  • All StdOut and StdErr caught on different levels to create flexibility in logging information

  • Console displays logging levels now

  • Everything captured in log-file, now in .csv format for structured reading.

  • Closes fix debug level logging #1239

image

Checklist

  • Keep pull requests small so they can be easily reviewed.
  • Update the documentation, please follow the numpy style guide.
  • Update tests.
  • Categorize the PR by setting a good title and adding one of the labels:
    bug, feature, ui, change, documentation, breaking, ci
    as they show up in the changelog.
  • Link this PR to related issues by using closing keywords.
  • Add a milestone to the PR for the intended release.
  • Request a review from another developer.

@mrvisscher mrvisscher added bug Issues/PRs related to bugs change PRs related to minor changes to AB labels Mar 7, 2024
@mrvisscher mrvisscher added this to the 2.10 milestone Mar 7, 2024
@mrvisscher mrvisscher requested a review from marc-vdm March 7, 2024 13:11
@mrvisscher mrvisscher marked this pull request as draft March 7, 2024 13:11
@mrvisscher mrvisscher marked this pull request as ready for review March 8, 2024 09:03
Provides the formats and initialization procedures for the logging streams.
This class will replace the filehandles of the supplied StdIO with own ones so changes to said stream can be caught.
It will instantiate a capturing thread that will read lines from the stream and log them using a logger called
"C/C++". The original StdIO filehandle is preserved so we can still write to it using the "write" method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the drugs you were taking when you came up with this. Is it really the best default logger name? Can we not at least namespace it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to share them with you one day.

But seriously, this is currently the only way to capture any QT logs as they are written directly to the stderr & stdout filehandles instead of through the Python implementation of them.

I'm impartial on the "C/C++" name if that's what you mean. It's mostly a clear indication that the stdio write was made from outside of Python.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As BW and the whole ecosystem becomes better developed, more and more logs will be created by libraries and apps. So my humble strong opinion is that the log names should clearly identify their origin, like "AB.layouts". Just "C/C++" might work for you for now, but "AB.pyside" is better looking forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree on you with that. Issue is that we cannot be sure that the write was actually made by Pyside. Any library writing directly to the io filehandles will end up under this logger, they are not identifiable anymore at that point.

Sure, right now I know only of PySide that's doing this. And when we move to a newer version this point is moot anyway, because PySide6 implements Python logging. But still it would be masking what the code is doing in truth: catching all C stdio writes.


from .logger import log
from .logger import log, exception_hook, log_file_location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, I think we should refactor the code base so we're not importing like this. Importing from .logger looks tacky. It would be better if we were importing like this I think:

from activity_browser.logger import ...
```

log.info(f'Activity Browser version: {version}')
if log_file_location:
log.info(f'The log file can be found at {log_file_location}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer string interpolation in logger functions

@mrvisscher mrvisscher merged commit b732c09 into LCA-ActivityBrowser:minor Jun 6, 2024
15 checks passed
@marc-vdm marc-vdm mentioned this pull request Jun 25, 2024
1 task
@mrvisscher mrvisscher deleted the logging-fixes branch November 22, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues/PRs related to bugs change PRs related to minor changes to AB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants