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

logging: add config for trace loggers and logging directory #118

Merged
merged 7 commits into from
Apr 21, 2022

Conversation

onerandomusername
Copy link
Member

  • allow configuring loggers and their specified levels

Some loggers can get spammy when debugging, this allows
turning them down, or setting other loggers to lower levels than the root

To use, set a MODMAIL_{level}_LOGGERS environment variable, delimiting
the loggers with ,
Valid levels are all of the valid levels for logging, as follows
trace, debug, info, notice, warning, error, critical

  • add support for configuring the file logging directory

The directory for logging files was fully dependent on the current
working directory
This caused my environment to be littered with logging directories

The solution to this was to continue to use the current working
directory, unless the parent directory of the bot is also a parent of
the cwd, in which case the bot parent directory is used for creating
the logging directory.

In addition, MODMAIL_LOGGING_DIRECTORY has been added as an override
environment variable. Setting it will use that directory for logging.

@onerandomusername onerandomusername added s: needs review Ready for review and merge t: enhancement Changes or improvements to existing features a: bot Catch all for issues regarding the bot labels Nov 16, 2021
@onerandomusername onerandomusername force-pushed the trace-loggers branch 2 times, most recently from 0847c18 to 7001b7f Compare November 16, 2021 11:59
@codecov
Copy link

codecov bot commented Nov 16, 2021

Codecov Report

Merging #118 (9c40668) into main (4b07917) will decrease coverage by 0.62%.
The diff coverage is 70.49%.

❗ Current head 9c40668 differs from pull request most recent head 2db6223. Consider uploading reports for the commit 2db6223 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   70.90%   70.28%   -0.63%     
==========================================
  Files          33       33              
  Lines        1619     1669      +50     
  Branches      199      207       +8     
==========================================
+ Hits         1148     1173      +25     
- Misses        439      461      +22     
- Partials       32       35       +3     
Impacted Files Coverage Δ
tests/modmail/test_log.py 76.47% <50.00%> (ø)
modmail/log.py 71.18% <67.30%> (-28.82%) ⬇️
modmail/__init__.py 100.00% <100.00%> (ø)
modmail/dispatcher.py 87.68% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a89f5d6...2db6223. Read the comment docs.

@onerandomusername onerandomusername force-pushed the trace-loggers branch 2 times, most recently from fc3611c to 97f349a Compare November 17, 2021 22:56
- allow configuring loggers and their specified levels

Some loggers can get spammy when debugging, this allows
turning them down, or setting other loggers to lower levels than the root

To use, set a MODMAIL_{level}_LOGGERS environment variable, delimiting
the loggers with `,`
Valid levels are all of the valid levels for logging, as follows
  trace, debug, info, notice, warning, error, critical

- add support for configuring the file logging directory

The directory for logging files was fully dependent on the current
working directory
This caused my environment to be littered with logging directories

The solution to this was to continue to use the current working
directory, unless the parent directory of the bot is also a parent of
the cwd, in which case the bot parent directory is used for creating
the logging directory.

In addition, `MODMAIL_LOGGING_DIRECTORY` has been added as an override
environment variable. Setting it will use that directory for logging.
modmail/log.py Outdated
This is applied for every logging level.
"""
env_vars = _get_env()
fmt_key = "MODMAIL_{level}_LOGGERS"
Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I'm not sure if this should be this format, or if MODMAIL_LOGGERS_{level} makes more sense since the variable is now more hierarchical.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to reverse this format, actually.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.3%) to 73.031% when pulling 2db6223 on trace-loggers into a89f5d6 on main.

@onerandomusername onerandomusername merged commit 8ba34ba into main Apr 21, 2022
@onerandomusername onerandomusername deleted the trace-loggers branch April 21, 2022 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: bot Catch all for issues regarding the bot s: needs review Ready for review and merge t: enhancement Changes or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants