Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vpsx
Copy link
Contributor

@vpsx vpsx commented Mar 25, 2019

The default log_level argument in get_logger is now NONE, which means the default level for new loggers is NOTSET. This means that child loggers whose levels were not explicitly set will inherit logging levels and handlers from ancestor loggers. This makes it easier to do things like toggle application-wide logging levels by just setting the level on the parent. Levels and handlers can still be set on child nodes by providing the log_level argument. // So now, for example, in a parent module you can do: logger = get_logger(__name__, log_level='debug'), and in child modules do logger = get_logger(__name__), and the child loggers will just inherit from the parent. Or, set a custom level for a child logger if desired; just supply log_level in the child instantiation. // https://docs.python.org/3/library/logging.html

Note: update this https://github.com/uc-cdis/authutils/releases wherever you update cdislogging

New Features

Breaking Changes

Default log_level arg in get_logger is now NONE; now you must explicitly set the log_level on the parent logger

Bug Fixes

Improvements

Dependency updates

Deployment changes

Copy link
Contributor

@Avantol13 Avantol13 left a comment

Choose a reason for hiding this comment

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

🙏 it'd be awesome if you could add to the README too on how to use this. e.g. Call get_logger(log_level='info') at top level and then get_logger() at child modules and it'll propogate <- of course you can expand on that but that's the important thing to note, that you MUST set the level at the top.

if logger.handlers:
return logger
if log_level:
if log_level not in log_levels:
Copy link
Contributor

Choose a reason for hiding this comment

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

if you wanna be fancy this can be one line if log_level and log_level not in log_levels:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tru. So then L89 has to turn into an elif?

if log_level and log_level not in log_levels: 
    [raise exception]
elif log_level:
    [set level]

This block just doesn't read well because the Exception part is big and then the set level part is a oneliner after a line break:

if log_level and log_level not in log_levels: 
    [raise exception]
    [is a longish]
    [block of code, vertically]
    [reader has forgotten about condition]
elif log_level:
    [set level]

So maybe I can do instead:

if log_level and log_level in log_levels:
    [set level]
elif log_level:
    [raise exception]
    [blah]
    [blah]

and I think that will be less backward and read better?
I confess I prefer the current "catch error if needed else continue" pattern to "if a and b (thing) elif just a (raise error)" but yeah it ends up pretty derpy just layout-wise

Copy link
Contributor

Choose a reason for hiding this comment

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

oh shoot, I didn't think this through or actually consider what was in the block. I also generally prefer the "catch error if needed and handle, continue" pattern to reduce the nesting where possible. but I'm sometimes privvy to the third option you provided too so the actual thing that should happen is first, so I guess I'm inconsistent 🤦‍♂️ you can effectively ignore me, any way is fine, not a huge deal

logger = cdislogging.get_logger('one_handler', log_level='debug')
assert len(logger.handlers) == 1

def test_inheritance():
Copy link
Contributor

Choose a reason for hiding this comment

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

First: yay unit tests!! :D second, I think we can break this test up into smaller tests. every time you try to log something new and assert something else could be a new test. I think it'd improve the readability a bit to chop this into pieces and add some docstrings for the tests

@Avantol13
Copy link
Contributor

Avantol13 commented Mar 26, 2019

Oh, and just noticed your PR description. General note, the different sections should ideally be summarized bullet points of changes (since we use these to generate release notes). you can add further detail in the top above all the sections or, in this case, I think you basically put the information you have in the PR description in the README. and then make the breaking change bullet really short and to the point, something like: top level logger now requires you to set a log_level

@vpsx vpsx merged commit 72ae3d4 into master Apr 12, 2019
@vpsx vpsx deleted the feat/propagate branch April 12, 2019 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants