geowatch.utils.util_logging module

Todo

  • [ ] This needs to be cleaned up. Python logging is way too global for my

taste. I would prefer something more instance level, but that will require some thought. The netharn.FitHarn has a way of accomplishing this that I reasonably like. That might be worth generalizing and porting here. But for now, this will remain somewhat ad-hoc.

geowatch.utils.util_logging.setup_logging(verbose=1)[source]

Define logging level

Parameters:

verbose (int) –

Accepted values:
  • 0: no logging

  • 1: INFO level

  • 2: DEBUG level

geowatch.utils.util_logging.get_logger(verbose=1)[source]
class geowatch.utils.util_logging.PrintLogger(name='<print-logger>', level=None, verbose=1)[source]

Bases: object

Simple print-based logger that duck-types the logging.Logger class and “simply works” without configuration.

Example

>>> from geowatch.utils.util_logging import *  # NOQA
>>> logger = PrintLogger(level=logging.INFO)
>>> logger.info('hello')
>>> logger.debug('world')
hello
>>> logger = PrintLogger(level=logging.DEBUG)
>>> logger.info('hello')
>>> logger.debug('world')
hello
world
setLevel(level)[source]
debug(msg, *args, **kwargs)[source]

Log ‘msg % args’ with severity ‘DEBUG’.

info(msg, *args, **kwargs)[source]

Log ‘msg % args’ with severity ‘INFO’.

warning(msg, *args, **kwargs)[source]

Log ‘msg % args’ with severity ‘WARNING’.

error(msg, *args, **kwargs)[source]

Log ‘msg % args’ with severity ‘ERROR’.

exception(msg, *args, exc_info=True, **kwargs)[source]

Convenience method for logging an ERROR with exception information.

critical(msg, *args, **kwargs)[source]

Log ‘msg % args’ with severity ‘CRITICAL’.

log(level, msg, *args, **kwargs)[source]

Log ‘msg % args’ with the integer severity ‘level’.

findCaller(stack_info=False, stacklevel=1)[source]

Find the stack frame of the caller so that we can note the source file name, line number and function name.

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)[source]

A factory method which can be overridden in subclasses to create specialized LogRecords.

filter(record)[source]
handle(record)[source]

Call the handlers for the specified record.

This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied.

addHandler(hdlr)[source]

Add the specified handler to this logger.

removeHandler(hdlr)[source]

Remove the specified handler from this logger.

hasHandlers()[source]

See if this logger has any handlers configured.

Loop through all handlers for this logger and its parents in the logger hierarchy. Return True if a handler was found, else False. Stop searching up the hierarchy whenever a logger with the “propagate” attribute set to zero is found - that will be the last logger which is checked for the existence of handlers.

callHandlers(record)[source]
getEffectiveLevel()[source]

Get the effective level for this logger.

isEnabledFor(level)[source]

Is this logger enabled for level ‘level’?

getChild(suffix)[source]