Skip to content

Application: add logging_config trait#698

Merged
blink1073 merged 3 commits intoipython:mainfrom
oliver-sanders:688
Apr 11, 2022
Merged

Application: add logging_config trait#698
blink1073 merged 3 commits intoipython:mainfrom
oliver-sanders:688

Conversation

@oliver-sanders
Copy link
Contributor

Closes #688

Allows fine configuration of logging via a logging.config.dictConfig, useful for configuring additional log handlers/formatters and advanced logging setups.

  • Fixes doctests and gets them running with pytest.
  • Unifies the pre-existing logging configurations into a standard "base" logging configuration dict.
  • Adds a new trait for providing a logging config dict which is merged into the "base" configuration allowing adding configs as well as redefining existing ones.
  • Changes the default logger level from WARN to DEBUG and the default handler level from undefined to WARN (I think the log_level should apply to the handler not the logger otherwise).

@blink1073
Copy link
Contributor

Hi @oliver-sanders, it looks like the switch to using black caused some merge conflicts.

The recommended way to handle this is to:

Run Black on modified files, keep a copy aside, start a new branch from "main", move the modified files back into place, and commit the result.

@oliver-sanders
Copy link
Contributor Author

Ok, that should do it, have kept a copy of the original branch for reference - https://github.com/ipython/traitlets/compare/main...oliver-sanders:688.20220411T1120?expand=1

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

This is great, thank you!

@blink1073
Copy link
Contributor

Looks like another doctest skip is needed:

 =================================== FAILURES ===================================
_______________ [doctest] traitlets.tests._warnings.all_warnings _______________
023     ...     warnings.warn(RuntimeWarning("bar"))
024 
025     We raise the warning once, while the warning filter is set to "once".
026     Hereafter, the warning is invisible, even with custom filters:
027     >>> with warnings.catch_warnings():
028     ...     warnings.simplefilter('once')
029     ...     foo()
030 
031     We can now run ``foo()`` without a warning being raised:
032     >>> from numpy.testing import assert_warns
UNEXPECTED EXCEPTION: ModuleNotFoundError("No module named 'numpy'")
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest traitlets.tests._warnings.all_warnings[3]>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

* Closes ipython#688
* Allows fine configuration of logging via a `logging.config.dictConfig`.
* Changes the default log level from WARN to DEBUG and the default log
  handler level from undefined to WARN.
@oliver-sanders
Copy link
Contributor Author

Looks like another doctest skip is needed:

Test was failing in CI because numpy dependency would be needed, added skips for now.

@blink1073
Copy link
Contributor

Thanks again! The downstream failure is being handled in #701

@Zsailer
Copy link
Member

Zsailer commented May 12, 2022

I think this might have broken some things: #722

I'll try to dive into this today/tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log: allow log handlers to be configured

3 participants