-
Notifications
You must be signed in to change notification settings - Fork 37
Change default log level to INFO #800
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
base: main
Are you sure you want to change the base?
Conversation
Remove default logging.basicConfig in Communication class init; it has no effect and should be set once in main.py anyway.
WalkthroughLogging configuration was adjusted in two places: communication.py now sets an instance-level logger to DEBUG instead of configuring the root logger, and main.py changes the file handler log level from DEBUG to INFO. No control flow or public API changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/python/main/ayab/engine/communication.py (1)
76-76
: Reconsider DEBUG as the default level.Setting the Communication logger to DEBUG by default creates a special case where this module's DEBUG messages appear on console while other modules are filtered at INFO. As noted in the PR description, this level might be better set to INFO to align with the root logger, or applied only when specifically needed for debugging.
Consider:
- Whether Communication truly needs DEBUG logging in normal operation
- If DEBUG is necessary for development, using an environment variable or configuration option to enable it selectively
- Setting to INFO to match the root logger's default behavior
Apply this diff if DEBUG logging should not be enabled by default:
- self.logger.setLevel(logging.DEBUG) + # Inherits INFO level from root logger; set to DEBUG only when debuggingOr configure it dynamically:
- self.logger.setLevel(logging.DEBUG) + # Set to DEBUG only if needed for debugging + import os + if os.getenv('AYAB_DEBUG'): + self.logger.setLevel(logging.DEBUG)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/python/main/ayab/engine/communication.py
(1 hunks)src/main/python/main/main.py
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Create and upload Linux AppImage release
- GitHub Check: Create and upload Windows build
- GitHub Check: run-pytest
- GitHub Check: Create and upload Mac OSX build
🔇 Additional comments (1)
src/main/python/main/main.py (1)
56-56
: Verify alignment with console handler level.Changing the root logger level to INFO is consistent with the PR objectives. However, the console handler on line 61 remains at DEBUG level. With the root logger at INFO, DEBUG messages from most loggers will be filtered out before reaching the console handler, making its DEBUG level largely ineffective.
Only loggers that explicitly override their level to DEBUG (like Communication in the other file) will have DEBUG messages reach the console.
Consider whether the console handler should also be set to INFO for clarity, or document why specific loggers need DEBUG console output while the default is INFO.
Based on learnings
Good catch on the extra In fact storing a logger in In any case, configuring the logger in the A better alternative would be to add a call to Regarding the default logging level, I agree that Keeping just the |
You could do something like illustrated below if you want to conditionally enable DEBUG level without a UI/preference file setting, in main.py: ...
logging.basicConfig(
filename=logfile,
level=logging.DEBUG if os.getenv('AYAB_DEBUG') else logging.INFO,
format="%(asctime)s %(name)-8s %(levelname)-8s %(message)s",
datefmt="%y-%m-%d %H:%M:%S",
)
console = logging.StreamHandler()
... => loglevel is INFO unless you define AYAB_DEBUG in your environment List of logging/logger.debug calls with suggested loglevel modification (first column) $ grep -r 'logging.debug' src/*
src/main/python/main/ayab/ayab.py: logging.debug("Quitting")
src/main/python/main/ayab/utils.py: logging.debug(f"MessageBox {message_type}: '{message}'")
src/main/python/main/ayab/gui_fsm.py: self.NO_IMAGE.entered.connect(lambda: logging.debug("Entered state NO_IMAGE"))
src/main/python/main/ayab/gui_fsm.py: lambda: logging.debug("Entered state TESTING_NO_IMAGE")
src/main/python/main/ayab/gui_fsm.py: lambda: logging.debug("Entered state CONFIGURING")
src/main/python/main/ayab/gui_fsm.py: self.CHECKING.entered.connect(lambda: logging.debug("Entered state CHECKING"))
src/main/python/main/ayab/gui_fsm.py: self.KNITTING.entered.connect(lambda: logging.debug("Entered state KNITTING"))
src/main/python/main/ayab/gui_fsm.py: self.TESTING.entered.connect(lambda: logging.debug("Entered state TESTING"))
$ grep -r 'logger.debug' src/*
src/main/python/main/ayab/firmware_flash.py: self.__logger.debug("port " + str(self.port))
src/main/python/main/ayab/firmware_flash.py: self.__logger.debug(exec_command)
src/main/python/main/ayab/version_checker.py: self.logger.debug(
src/main/python/main/ayab/version_checker.py: self.logger.debug("Getting %s", latest_relase_url)
src/main/python/main/ayab/version_checker.py: self.logger.debug(
src/main/python/main/ayab/version_checker.py: self.logger.debug("Latest version is %s at %s", latest_version, url)
src/main/python/main/ayab/version_checker.py: self.logger.debug("Cleaning up")
W src/main/python/main/ayab/engine/communication.py: self.logger.debug("unknown message: ") # drop crlf
src/main/python/main/ayab/engine/control.py: self.logger.debug(msg)
src/main/python/main/ayab/engine/control.py: self.logger.debug("sending blank line as final line=%d", requested_line)
src/main/python/main/ayab/engine/mode.py: control.logger.debug("COLOR " + str(color))
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State CONNECT")
src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("Port name: " + control.portname)
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State VERSION_CHECK")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State INIT")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State REQUEST_TEST")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State REQUEST_START")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State CONFIRM_START")
W src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug(
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State RUN_KNIT")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State CONFIRM_TEST")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State RUN_TEST")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State DISCONNECT")
I src/main/python/main/ayab/engine/engine_fsm.py: control.logger.debug("State FINISHED")
src/main/python/main/ayab/engine/engine.py: self.__logger.debug(self.config.as_dict()) |
Remove default logging.basicConfig in Communication class init; it has no effect and should be set once in main.py anyway.
The DEBUG log level should not be set in the root log as it may be used as the default for other modules and thus unnecessarily increase verbosity.
I added a setlevel(DEBUG) to the Communication's logger to keep the intended DEBUG level there but this should probably be set to INFO as well (or removed, added when required/while debugging).
Summary by CodeRabbit