Skip to content
Back to top
View this page

# Picologging API

class picologging.FileHandler(filename, mode='a', encoding=None, delay=False, errors=None)

  A handler class which writes formatted logging records to disk files.

  close()

    Closes the stream.

  emit(record)

    Emit a record.

    If the stream was not opened because ‘delay’ was specified in the constructor, open it before calling the superclass’s emit.

class picologging.Filterer

  Filterer interface.

  addFilter(object, /)

    Add a filter to the logger.

  filter(object, /)

    Filter a record.

  filters

    Filters

  removeFilter(object, /)

    Remove a filter from the logger.

class picologging.FormatStyle

  Formatter for log records.

  format(object, /)

    Get message

  usesTime()

    Get message

  validate()

    Get message

class picologging.Formatter

  Formatter for log records.

  datefmt

    Date format string

  format(object, /)

    Format record into log event string

  formatException(object, /)

    Format and return the specified exception information as a string.

  formatMessage(object, /)

    Format the message for a record.

  formatStack(object, /)

    Format the stack for a record.

  usesTime()

    Return True if the format uses the creation time of the record.

class picologging.Handler

  Handler interface.

  acquire()

    Acquire the lock.

  close()

    Tidy up any resources used by the handler.

  createLock()

    Create a new lock instance.

  emit(object, /)

    Emit a record.

  flush()

    Ensure all logging output has been flushed.

  format(object, /)

    Format a record.

  formatter

    Handler formatter

  get_name()

    Get the name of the handler.

  handle(object, /)

    Handle a record.

  handleError(object, /)

    Handle an error during an emit().

  level

    Handler level

  name

    Handler name

  release()

    Release the lock.

  setFormatter(object, /)

    Set the formatter of the handler.

  setLevel(object, /)

    Set the level of the handler.

  set_name(object, /)

    Set the name of the handler.

class picologging.LogRecord

  LogRecord objects are used to hold information about log events.

  args

    Arguments (tuple)

  asctime

    Asctime

  created

    Created

  exc_info

    Exception info

  exc_text

    Exception text

  filename

    File name

  funcName

    Function name

  getMessage()

    Get message

  levelname

    Level name

  levelno

    Level number

  lineno

    Line number

  message

    Message

  module

    Module name

  msecs

    Milliseconds

  msg

    Message (string)

  name

    Logger name

  pathname

    File pathname

  process

    Process

  processName

    Process name

  relativeCreated

    Relative created

  stack_info

    Stack info

  thread

    Thread

  threadName

    Thread name

class picologging.Logger

  Logging interface.

  addHandler(object, /)

    Add a handler to the logger.

  critical()

    Log a message at level CRITICAL.

  debug()

    Log a message at level DEBUG.

  disabled

    Logger disabled

  error()

    Log a message at level ERROR.

  exception()

    Log a message at level ERROR.

  fatal()

    Log a message at level FATAL.

  getEffectiveLevel()

    Get the effective level of the logger.

  handlers

    Logger handlers

  info()

    Log a message at level INFO.

  isEnabledFor(object, /)

    Check if logger enabled for this level.

  level

    Logger level

  log()

    Log a message at the specified level.

  manager

    Logger manager

  name

    Logger name

  parent

    Logger parent

  propagate

    Logger propagate

  removeHandler(object, /)

    Remove a handler from the logger.

  setLevel(object, /)

    Set the level of the logger.

  warning()

    Log a message at level WARNING.

class picologging.Manager(rootnode, cls=None)

  There is [under normal circumstances] just one Manager instance, which holds the hierarchy of loggers.

  property disable
  getLogger(name)

    Get a logger with the specified name (channel name), creating it if it doesn’t yet exist. This name is a dot-separated hierarchical name, such as “a”, “a.b”, “a.b.c” or similar.

  setLogRecordFactory(factory)
  setLoggerClass(klass)

class picologging.NullHandler

  This handler does nothing. It’s intended to be used to avoid the “No handlers could be found for logger XXX” one-off warning. This is important for library code, which may contain code to log events. If a user of the library does not configure logging, the one-off warning might be produced; to avoid this, the library developer simply needs to instantiate a NullHandler and add it to the top-level logger of the library module or package.

  emit(record)

    Stub.

  handle(record)

    Stub.

class picologging.PercentStyle(*args, **kwargs)

class picologging.StrFormatStyle(*args, **kwargs)

class picologging.StreamHandler

  StreamHandler interface.

  emit()

    Emit a record.

  flush()

    Flush the stream.

  setStream(object, /)

    Set the stream to write to.

  stream

    Stream

picologging.basicConfig(**kwargs)

  Do basic configuration for the logging system.

  This function does nothing if the root logger already has handlers configured, unless the keyword argument force is set to `True`. It is a convenience method intended for use by simple scripts to do one-shot configuration of the logging package.

  The default behaviour is to create a StreamHandler which writes to sys.stderr, set a formatter using the BASIC_FORMAT format string, and add the handler to the root logger.

  A number of optional keyword arguments may be specified, which can alter the default behaviour.

  filename Specifies that a FileHandler be created, using the specified

    filename, rather than a StreamHandler.

  filemode Specifies the mode to open the file, if filename is specified

    (if filemode is unspecified, it defaults to ‘a’).

  format Use the specified format string for the handler. datefmt Use the specified date/time format. style If a format string is specified, use this to specify the

  > type of format string (possible values ‘%’, ‘{’, ‘$’, for %-formatting, `str.format()` and `string.Template` - defaults to ‘%’).

  level Set the root logger level to the specified level. stream Use the specified stream to initialize the StreamHandler. Note

  > that this argument is incompatible with ‘filename’ - if both are present, ‘stream’ is ignored.

  handlers If specified, this should be an iterable of already created

    handlers, which will be added to the root handler. Any handler in the list which does not have a formatter assigned will be assigned the formatter created in this function.

  force If this keyword is specified as true, any existing handlers

    attached to the root logger are removed and closed, before carrying out the configuration as specified by the other arguments.

  encoding If specified together with a filename, this encoding is passed to

    the created FileHandler, causing it to be used when the file is opened.

  errors If specified together with a filename, this value is passed to the

    created FileHandler, causing it to be used when the file is opened in text mode. If not specified, the default value is backslashreplace.

  Note that you could specify a stream created using open(filename, mode) rather than passing the filename and mode in. However, it should be remembered that StreamHandler does not close its stream (since it may be using sys.stdout or sys.stderr), whereas FileHandler closes its stream when the handler is closed.

  Changed in version 3.2: Added the `style` parameter.

  Changed in version 3.3: Added the `handlers` parameter. A `ValueError` is now thrown for incompatible arguments (e.g. `handlers` specified together with `filename`/`filemode`, or `filename`/`filemode` specified together with `stream`, or `handlers` specified together with `stream`.

  Changed in version 3.8: Added the `force` parameter.

  Changed in version 3.9: Added the `encoding` and `errors` parameters.

picologging.critical(msg, *args, **kwargs)

  Log a message with severity ‘CRITICAL’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.

picologging.debug(msg, *args, **kwargs)

  Log a message with severity ‘DEBUG’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.

picologging.disable(level=50)

  Disable all logging calls of severity ‘level’ and below.

picologging.error(msg, *args, **kwargs)

  Log a message with severity ‘ERROR’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.

picologging.exception(msg, *args, exc_info=True, **kwargs)

  Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.

picologging.fatal(msg, *args, **kwargs)

  Don’t use this function, use critical() instead.

picologging.getLogger(name=None)

  Return a logger with the specified name, creating it if necessary.

  If no name is specified, return the root logger.

picologging.info(msg, *args, **kwargs)

  Log a message with severity ‘INFO’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.

picologging.log(level, msg, *args, **kwargs)

  Log ‘msg % args’ with the integer severity ‘level’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.

picologging.makeLogRecord(dict)

  Make a LogRecord whose attributes are defined by the specified dictionary, This function is useful for converting a logging event received over a socket connection (which is sent as a dictionary) into a LogRecord instance.

picologging.warn(msg, *args, **kwargs)

picologging.warning(msg, *args, **kwargs)

  Log a message with severity ‘WARNING’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.