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

Test loggers with NOTSET level having the parent level changed after instantiation #22

Closed
tonybaloney opened this issue Jun 23, 2022 · 3 comments
Assignees

Comments

@tonybaloney
Copy link
Contributor

Assert that:

  • You can create a logger with level NOTSET
  • You can have a parent with a high level, e.g. WARNING
  • You can raise a DEBUG message that is not handled
  • You can change the level of the parent to DEBUG
  • You can raise a DEBUG message in the child that IS handled
@aminalaee
Copy link
Contributor

I might be missing something but even the standard library logging doesn't assert this:

def test_case():
    logger = logging.Logger("test")
    logger.parent = logging.Logger("parent", logging.WARNING)

    stream = io.StringIO()
    handler = logging.StreamHandler(stream)
    logger.addHandler(handler)

    logger.log(logging.DEBUG, "Hello World")
    assert stream.getvalue() == ""

    logger.parent.setLevel(logging.DEBUG)

    logger.log(logging.DEBUG, "Hello World")
    assert stream.getvalue() == "Hello World\n"  # Failing

And then the test with picologging has the same behaviour and does not pass either.

pamelafox added a commit to pamelafox/picologging that referenced this issue Oct 10, 2022
@pamelafox
Copy link
Member

I've actually added the suggested situation in my latest PR, https://github.com/microsoft/picologging/pull/108/files#diff-7c31002b037ae4bc2888350bb25d9b9621c6aff7e98d6e6871a8a649d088e27bR516
I changed the test to use getLogger and dots in the name for parent setting, as the logging library does not encourage directly using the constructor or directly setting the parent. With those changes, the test passes in stdlib and my branch.

@pamelafox pamelafox self-assigned this Oct 10, 2022
@pamelafox
Copy link
Member

Change merged!

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

No branches or pull requests

3 participants