Although `Logger.exception` supports passing exception info with
`exc_info`, when you use `logging.exception` keyword arguments are not
forwarded to the root logger, which makes passing `exc_info` raise
`TypeError`.
Signed-off-by: Nick Budak <thatbudakguy@gmail.com>
This commit allows for logging handlers to be added to the root logger
and then used by non-root loggers that don't have their own handlers.
It also adds the (CPython-compatible) handlers argument
to logging.basicConfig() to ease this initialization:
import logging
sh = logging.StreamHandler()
fh = logging.FileHandler("my.log", mode="a")
logging.basicConfig(handlers=[sh, fh])
root_logger = logging.getLogger() # uses sh and fh
another_logger = logging.getLogger("another") # inherits handlers
It also adds the Logger.removeHandler() method and avoids repeated handler
addition.
It also adds the flush() method to StreamHandler and its subclasses.
It also correctly calls the superclass constructor from the StreamHandler
constructor and uses a default formatter if a Handler has none
set (as in PR #710).
Signed-off-by: Ned Konz <ned@productcreationstudio.com>
This commit allows you to pass an exception object in as the exc_info kwarg
(CPython allows this), so logging exceptions can work even if the
MICROPY_PY_SYS_EXC_INFO option is disabled in the firmware.
Separately to that, currently even when sys.exc_info() is enabled, it's
only printing the traceback to _stream = sys.stderr - not to the configured
logging handlers. This means for instance if you've got a file log
handler it misses out on the tracebacks. That's also fixed in this commit.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Previously a child logger just uses the global default when unset.
Modified to matches the CPython behavior of using the parent's level.
Also implemented CPython's getEffectiveLevel() which provides a convenient
way to implement this. In our version, we only ever have one parent
(the root), so it only has to recurse one level.
Also set the default level to WARNING to match CPython.
Updated the examples to highlight the differences (but they now match).
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Add support for all format specifiers, support for `datefmt` using
(optional) strftime, and support for Stream and File handlers.
Ports/boards that need to use `FileHandlers` should enable
`MICROPY_PY_SYS_ATEXIT`, and enabled `MICROPY_PY_SYS_EXC_INFO` if using
`logging.exception()`.