__init__.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # -*- test-case-name: twisted.logger.test -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Twisted Logger: Classes and functions to do granular logging.
  6. Example usage in a module C{some.module}::
  7. from twisted.logger import Logger
  8. log = Logger()
  9. def handleData(data):
  10. log.debug("Got data: {data!r}.", data=data)
  11. Or in a class::
  12. from twisted.logger import Logger
  13. class Foo:
  14. log = Logger()
  15. def oops(self, data):
  16. self.log.error("Oops! Invalid data from server: {data!r}",
  17. data=data)
  18. C{Logger}s have namespaces, for which logging can be configured independently.
  19. Namespaces may be specified by passing in a C{namespace} argument to L{Logger}
  20. when instantiating it, but if none is given, the logger will derive its own
  21. namespace by using the module name of the callable that instantiated it, or, in
  22. the case of a class, by using the fully qualified name of the class.
  23. In the first example above, the namespace would be C{some.module}, and in the
  24. second example, it would be C{some.module.Foo}.
  25. @var globalLogPublisher: The L{LogPublisher} that all L{Logger} instances that
  26. are not otherwise parameterized will publish events to by default.
  27. @var globalLogBeginner: The L{LogBeginner} used to activate the main log
  28. observer, whether it's a log file, or an observer pointing at stderr.
  29. """
  30. __all__ = [
  31. # From ._levels
  32. "InvalidLogLevelError",
  33. "LogLevel",
  34. # From ._format
  35. "formatEvent",
  36. "formatEventAsClassicLogText",
  37. "formatTime",
  38. "timeFormatRFC3339",
  39. "eventAsText",
  40. # From ._flatten
  41. "extractField",
  42. # From ._interfaces
  43. "ILogObserver",
  44. "LogEvent",
  45. # From ._logger
  46. "Logger",
  47. "_loggerFor",
  48. # From ._observer
  49. "LogPublisher",
  50. # From ._buffer
  51. "LimitedHistoryLogObserver",
  52. # From ._file
  53. "FileLogObserver",
  54. "textFileLogObserver",
  55. # From ._filter
  56. "PredicateResult",
  57. "ILogFilterPredicate",
  58. "FilteringLogObserver",
  59. "LogLevelFilterPredicate",
  60. # From ._stdlib
  61. "STDLibLogObserver",
  62. # From ._io
  63. "LoggingFile",
  64. # From ._legacy
  65. "LegacyLogObserverWrapper",
  66. # From ._global
  67. "globalLogPublisher",
  68. "globalLogBeginner",
  69. "LogBeginner",
  70. # From ._json
  71. "eventAsJSON",
  72. "eventFromJSON",
  73. "jsonFileLogObserver",
  74. "eventsFromJSONLogFile",
  75. # From ._capture
  76. "capturedLogs",
  77. ]
  78. from ._levels import InvalidLogLevelError, LogLevel
  79. from ._flatten import extractField
  80. from ._format import (
  81. formatEvent,
  82. formatEventAsClassicLogText,
  83. formatTime,
  84. timeFormatRFC3339,
  85. eventAsText,
  86. )
  87. from ._interfaces import ILogObserver, LogEvent
  88. from ._logger import Logger, _loggerFor
  89. from ._observer import LogPublisher
  90. from ._buffer import LimitedHistoryLogObserver
  91. from ._file import FileLogObserver, textFileLogObserver
  92. from ._filter import (
  93. PredicateResult,
  94. ILogFilterPredicate,
  95. FilteringLogObserver,
  96. LogLevelFilterPredicate,
  97. )
  98. from ._stdlib import STDLibLogObserver
  99. from ._io import LoggingFile
  100. from ._legacy import LegacyLogObserverWrapper
  101. from ._global import globalLogPublisher, globalLogBeginner, LogBeginner
  102. from ._json import (
  103. eventAsJSON,
  104. eventFromJSON,
  105. jsonFileLogObserver,
  106. eventsFromJSONLogFile,
  107. )
  108. from ._capture import capturedLogs