jgdv.logging.context

Classes

LogContext

a really simple wrapper to set a logger's level, then roll it back

TempLogger

For using a specific type of logger in a context, or getting

Module Contents

class jgdv.logging.context.LogContext(logger, level=None)[source]

a really simple wrapper to set a logger’s level, then roll it back

use as: with LogContext(logger, level=logmod.INFO) as ctx: ctx.log(“blah”) # or logger.info(“blah”)

Parameters:
  • logger (jgdv.logging._interface.Logger)

  • level (jgdv.Maybe[int])

log(msg, *args, **kwargs) <Unknown>[source]
Parameters:
  • msg (str)

  • args (Any)

  • kwargs (Any)

Return type:

None

_level_stack
_logger
_original_level
_temp_level
class jgdv.logging.context.TempLogger(logger)[source]

For using a specific type of logger in a context, or getting a custom logger class without changing it globally

use as: with TempLogger(MyLoggerClass) as ctx: # Either: ctx[‘name’].info(…) # or: logmod.getLogger(‘name’).info(…)

Parameters:

logger (type[jgdv.logging._interface.Logger])

_original: jgdv.Maybe[type[jgdv.logging._interface.Logger]]
_target_cls: type[jgdv.logging._interface.Logger]