Picologging API#

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

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

close()[source]#

Closes the stream.

emit(record)[source]#

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()#

Add a filter to the logger.

filter()#

Filter a record.

filters#

Filters

removeFilter()#

Remove a filter from the logger.

class picologging.FormatStyle#

Formatter for log records.

format()#

Get message

usesTime()#

Get message

validate()#

Get message

class picologging.Formatter#

Formatter for log records.

datefmt#

Date format string

format()#

Format record into log event string

formatException()#

Format and return the specified exception information as a string.

formatMessage()#

Format the message for a record.

formatStack()#

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()#

Emit a record.

flush()#

Ensure all logging output has been flushed.

format()#

Format a record.

formatter#

Handler formatter

get_name()#

Get the name of the handler.

handle()#

Handle a record.

handleError()#

Handle an error during an emit().

level#

Handler level

name#

Handler name

release()#

Release the lock.

setFormatter()#

Set the formatter of the handler.

setLevel()#

Set the level of the handler.

set_name()#

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()#

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()#

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()#

Remove a handler from the logger.

setLevel()#

Set the level of the logger.

warning()#

Log a message at level WARNING.

class picologging.Manager(rootnode, cls=None)[source]#

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

property disable#
getLogger(name)[source]#

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)[source]#
setLoggerClass(klass)[source]#
class picologging.NullHandler[source]#

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)[source]#

Stub.

handle(record)[source]#

Stub.

class picologging.PercentStyle(*args, **kwargs)[source]#
class picologging.StrFormatStyle(*args, **kwargs)[source]#
class picologging.StreamHandler#

StreamHandler interface.

emit()#

Emit a record.

flush()#

Flush the stream.

setStream()#

Set the stream to write to.

stream#

Stream

picologging.basicConfig(**kwargs)[source]#

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)[source]#

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)[source]#

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)[source]#

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

picologging.error(msg, *args, **kwargs)[source]#

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)[source]#

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)[source]#

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

picologging.getLogger(name=None)[source]#

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)[source]#

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)[source]#

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)[source]#

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)[source]#
picologging.warning(msg, *args, **kwargs)[source]#

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.