class documentation

class twisted.logger.Logger: (source)

View In Hierarchy

A Logger emits log messages to an observer. You should instantiate it as a class or module attribute, as documented in this module's documentation.

Instance Variable namespace the namespace for this logger
Instance Variable source The object which is emitting events via this logger
Instance Variable observer The observer that this logger will send events to.
Method __init__ No summary
Method __get__ When used as a descriptor, i.e.:
Method __repr__ Undocumented
Method emit Emit a log event to all log observers at the given level.
Method failure Log a failure and emit a traceback.
Method debug Emit a log event at log level LogLevel.debug.
Method info Emit a log event at log level LogLevel.info.
Method warn Emit a log event at log level LogLevel.warn.
Method error Emit a log event at log level LogLevel.error.
Method critical Emit a log event at log level LogLevel.critical.
Static Method _namespaceFromCallingContext Derive a namespace from the module containing the caller's caller.
namespace = (source)
the namespace for this logger
source = (source)
The object which is emitting events via this logger
observer = (source)
The observer that this logger will send events to.
@staticmethod
def _namespaceFromCallingContext(): (source)

Derive a namespace from the module containing the caller's caller.

Returnsthe fully qualified python name of a module. (type: str)
def __init__(self, namespace=None, source=None, observer=None): (source)
ParametersnamespaceThe namespace for this logger. Uses a dotted notation, as used by python modules. If not None, then the name of the module of the caller is used. (type: Optional[str])
sourceThe object which is emitting events via this logger; this is automatically set on instances of a class if this Logger is an attribute of that class. (type: Optional[object])
observerThe observer that this logger will send events to. If None, use the global log publisher. (type: Optional[ILogObserver])
def __get__(self, instance, owner=None): (source)

When used as a descriptor, i.e.:

    # File: athing.py
    class Something:
        log = Logger()
        def hello(self):
            self.log.info("Hello")

a Logger's namespace will be set to the name of the class it is declared on. In the above example, the namespace would be athing.Something.

Additionally, its source will be set to the actual object referring to the Logger. In the above example, Something.log.source would be Something, and Something().log.source would be an instance of Something.

ParametersinstanceUndocumented (type: object)
ownerUndocumented (type: Optional[type])
ReturnsUndocumented (type: object)
def __repr__(self): (source)

Undocumented

ReturnsUndocumented (type: str)
def emit(self, level, format=None, **kwargs): (source)

Emit a log event to all log observers at the given level.

Parameterslevela LogLevel (type: LogLevel)
formata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def failure(self, format, failure=None, level=LogLevel.critical, **kwargs): (source)

Log a failure and emit a traceback.

For example:

    try:
        frob(knob)
    except Exception:
        log.failure("While frobbing {knob}", knob=knob)

or:

    d = deferredFrob(knob)
    d.addErrback(lambda f: log.failure("While frobbing {knob}",
                                       f, knob=knob))

This method is generally meant to capture unexpected exceptions in code; an exception that is caught and handled somehow should be logged, if appropriate, via Logger.error instead. If some unknown exception occurs and your code doesn't know how to handle it, as in the above example, then this method provides a means to describe the failure in nerd-speak. This is done at LogLevel.critical by default, since no corrective guidance can be offered to an user/administrator, and the impact of the condition is unknown.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: str)
failurea Failure to log. If None, a Failure is created from the exception in flight. (type: Optional[Failure])
levela LogLevel to use. (type: LogLevel)
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def debug(self, format=None, **kwargs): (source)

Emit a log event at log level LogLevel.debug.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def info(self, format=None, **kwargs): (source)

Emit a log event at log level LogLevel.info.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def warn(self, format=None, **kwargs): (source)

Emit a log event at log level LogLevel.warn.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def error(self, format=None, **kwargs): (source)

Emit a log event at log level LogLevel.error.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
def critical(self, format=None, **kwargs): (source)

Emit a log event at log level LogLevel.critical.

Parametersformata message format using new-style (PEP 3101) formatting. The logging event (which is a dict) is used to render this format string. (type: Optional[str])
kwargsadditional key/value pairs to include in the event. Note that values which are later mutated may result in non-deterministic behavior from observers that schedule work for later execution. (type: object)
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.