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

Write logs to cbi.log by default #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Pennycook
Copy link
Contributor

Related issues

First part of the solution to #108. I'll open a separate PR with my proposed WarningAggregator class once this is merged.

Proposed changes

  • Write logs to file ("cbi.log") and the terminal simultaneously, by configuring two handlers.
  • Switch the default logging level from ERROR to WARNING, so that warnings are not printed to the terminal by default.

There is no need to call logging.getLogger("codebasin") each time we use
the logger; we can adopt the convention used by other parts of the code.

Signed-off-by: John Pennycook <john.pennycook@intel.com>
@Pennycook Pennycook added the enhancement New feature or request label Sep 19, 2024
@Pennycook Pennycook added this to the 2.0.0 milestone Sep 19, 2024
- All messages are written to a log file ("cbi.log")
- Only errors are written to the terminal by default
- Messages written to terminal are based on -q and -v flags

Signed-off-by: John Pennycook <john.pennycook@intel.com>
file_handler.setFormatter(formatter)
log.addHandler(file_handler)
log_path = os.path.realpath("cbi.log")
print(f"Log file created at {log_path}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you not just log this after you've set up the stdout handler?

@@ -243,5 +257,5 @@ def report_enabled(name):
sys.argv[0] = "codebasin"
main()
except Exception as e:
logging.getLogger("codebasin").error(str(e))
log.error(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this purposefully done to not include the traceback? Otherwise you can do log.exception(e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants