aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Twisted/py3/twisted/logger/__init__.py
blob: 62f2f71f4e3d9ad3f89d02641d758bc37a09f779 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- test-case-name: twisted.logger.test -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Twisted Logger: Classes and functions to do granular logging.

Example usage in a module C{some.module}::

    from twisted.logger import Logger
    log = Logger()

    def handleData(data):
        log.debug("Got data: {data!r}.", data=data)

Or in a class::

    from twisted.logger import Logger

    class Foo:
        log = Logger()

        def oops(self, data):
            self.log.error("Oops! Invalid data from server: {data!r}",
                           data=data)

C{Logger}s have namespaces, for which logging can be configured independently.
Namespaces may be specified by passing in a C{namespace} argument to L{Logger}
when instantiating it, but if none is given, the logger will derive its own
namespace by using the module name of the callable that instantiated it, or, in
the case of a class, by using the fully qualified name of the class.

In the first example above, the namespace would be C{some.module}, and in the
second example, it would be C{some.module.Foo}.

@var globalLogPublisher: The L{LogPublisher} that all L{Logger} instances that
    are not otherwise parameterized will publish events to by default.
@var globalLogBeginner: The L{LogBeginner} used to activate the main log
    observer, whether it's a log file, or an observer pointing at stderr.
"""

__all__ = [
    # From ._levels
    "InvalidLogLevelError",
    "LogLevel",
    # From ._format
    "formatEvent",
    "formatEventAsClassicLogText",
    "formatTime",
    "timeFormatRFC3339",
    "eventAsText",
    # From ._flatten
    "extractField",
    # From ._interfaces
    "ILogObserver",
    "LogEvent",
    # From ._logger
    "Logger",
    "_loggerFor",
    # From ._observer
    "LogPublisher",
    # From ._buffer
    "LimitedHistoryLogObserver",
    # From ._file
    "FileLogObserver",
    "textFileLogObserver",
    # From ._filter
    "PredicateResult",
    "ILogFilterPredicate",
    "FilteringLogObserver",
    "LogLevelFilterPredicate",
    # From ._stdlib
    "STDLibLogObserver",
    # From ._io
    "LoggingFile",
    # From ._legacy
    "LegacyLogObserverWrapper",
    # From ._global
    "globalLogPublisher",
    "globalLogBeginner",
    "LogBeginner",
    # From ._json
    "eventAsJSON",
    "eventFromJSON",
    "jsonFileLogObserver",
    "eventsFromJSONLogFile",
    # From ._capture
    "capturedLogs",
]

from ._levels import InvalidLogLevelError, LogLevel

from ._flatten import extractField

from ._format import (
    formatEvent,
    formatEventAsClassicLogText,
    formatTime,
    timeFormatRFC3339,
    eventAsText,
)

from ._interfaces import ILogObserver, LogEvent

from ._logger import Logger, _loggerFor

from ._observer import LogPublisher

from ._buffer import LimitedHistoryLogObserver

from ._file import FileLogObserver, textFileLogObserver

from ._filter import (
    PredicateResult,
    ILogFilterPredicate,
    FilteringLogObserver,
    LogLevelFilterPredicate,
)

from ._stdlib import STDLibLogObserver

from ._io import LoggingFile

from ._legacy import LegacyLogObserverWrapper

from ._global import globalLogPublisher, globalLogBeginner, LogBeginner

from ._json import (
    eventAsJSON,
    eventFromJSON,
    jsonFileLogObserver,
    eventsFromJSONLogFile,
)

from ._capture import capturedLogs