-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
Add a custom log handler #6900
base: main
Are you sure you want to change the base?
Add a custom log handler #6900
Conversation
self.setObjectName('LogDialog') | ||
self.setWindowTitle(trans._('napari log')) | ||
self.setWindowModality(Qt.WindowModality.ApplicationModal) | ||
self.exec_() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exec should not be called in constructor, but in calling place.
@@ -42,6 +44,8 @@ | |||
'viewer': ['Viewer', 'current_viewer'], | |||
} | |||
|
|||
_LOG_STREAM = _get_custom_log_stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that custom log handler should be initialized in napari.qt.qt_event_loop
, same as notification manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the logger should work regardless of qt right? Also headless it would be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, it is log handler, not logger. The current code means, that each time one import napari it starts storing all logs in memory, even without a clean way to show them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... but isn't that what we want? Would be good to be able to get these logs programmatically as well. We can also discard old logs if we go above a certain size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal feeling is that we should do this, like with notifications (warnigs), but I may be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do what? I'm not sure I follow ^^'
logger = logging.getLogger('napari') | ||
logger.setLevel(logging.DEBUG) | ||
logger.addHandler(handler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be nice to connect to all loggers and be able to filter messages based on logger (so someone could filter logs only from a given plugin logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True... I'm not sure how to do that though; I guess we somehow get the root logger? And btw, is there a way to get these logging parameters (level, thread, etc) "raw" instead of formatting to string and then de-formatting?
References and relevant issues
Followup on #6849 (comment)
Description
The idea is to have our own custom handler for log messages so we can then expose the logs as we prefer from the GUI. This will make it easier for users to copy-paste logs even if they didn't manually open from the console, and also easier for developers to quickly check things.
I never really worked with the logging module, so I have a feeling that this is garbage... but oh well, let's see how bad :P
To test, open napari and do some stuff. Then, from the terminal or console run:
EDIT: Added a very quick-and-dirty GUI for the logger based on the implementation of the
About
widget. For how bad it is, it's actually ok xD You can open it from the menu `Help -> Show log".cc @Czaki