finesse.utilities.logging.logs¶
- finesse.utilities.logging.logs(logger, level=None, handler=None, close=True)[source]¶
Emit logs at or above level in the encapsulated context, optionally using the specified handler.
See the Python logging cookbook for more information.
- Parameters
- logger
logging.Logger
The logger to use for the encapsulated context.
- levelstr or int, optional
The minimum log levels to emit. The standard log levels “debug”, “info”, “warning”, “error” and “critical” are supported, as are their corresponding level numbers (see
logging
).- handler
logging.LogHandler
, optional The handler to add to logger for the encapsulated context.
- closebool, optional
Close handler once finished. Defaults to True.
- logger
Examples
Print debug logs during parsing, excluding compilation messages.
>>> import logging >>> from finesse import Model >>> from finesse.utilities import logs >>> from finesse.utilities.logging import FinesseStreamHandler >>> handler = FinesseStreamHandler() >>> handler.exclude("finesse.script.compiler") >>> model = Model() >>> with logs(logging.getLogger(), level="debug", handler=handler): >>> model.parse("laser l1 P=1")