An object to dispatch logging messages to configured handlers. The |Logger| is the core object of ``loguru``, every logging configuration and usage pass through a call to one of its methods. There is only one logger, so there is no need to retrieve one before usage. Once the ``logg
| 211 | |
| 212 | |
| 213 | class Logger: |
| 214 | """An object to dispatch logging messages to configured handlers. |
| 215 | |
| 216 | The |Logger| is the core object of ``loguru``, every logging configuration and usage pass |
| 217 | through a call to one of its methods. There is only one logger, so there is no need to retrieve |
| 218 | one before usage. |
| 219 | |
| 220 | Once the ``logger`` is imported, it can be used to write messages about events happening in your |
| 221 | code. By reading the output logs of your application, you gain a better understanding of the |
| 222 | flow of your program and you more easily track and debug unexpected behaviors. |
| 223 | |
| 224 | Handlers to which the logger sends log messages are added using the |add| method. Note that you |
| 225 | can use the |Logger| right after import as it comes pre-configured (logs are emitted to |
| 226 | |sys.stderr| by default). Messages can be logged with different severity levels and they can be |
| 227 | formatted using curly braces (it uses |str.format| under the hood). |
| 228 | |
| 229 | When a message is logged, a "record" is associated with it. This record is a dict which contains |
| 230 | information about the logging context: time, function, file, line, thread, level... It also |
| 231 | contains the ``__name__`` of the module, this is why you don't need named loggers. |
| 232 | |
| 233 | You should not instantiate a |Logger| by yourself, use ``from loguru import logger`` instead. |
| 234 | """ |
| 235 | |
| 236 | def __init__(self, core, exception, depth, record, lazy, colors, raw, capture, patchers, extra): |
| 237 | self._core = core |
| 238 | self._options = (exception, depth, record, lazy, colors, raw, capture, patchers, extra) |
| 239 | |
| 240 | def __repr__(self): |
| 241 | return "<loguru.logger handlers=%r>" % list(self._core.handlers.values()) |
| 242 | |
| 243 | def add( |
| 244 | self, |
| 245 | sink, |
| 246 | *, |
| 247 | level=_defaults.LOGURU_LEVEL, |
| 248 | format=_defaults.LOGURU_FORMAT, |
| 249 | filter=_defaults.LOGURU_FILTER, |
| 250 | colorize=_defaults.LOGURU_COLORIZE, |
| 251 | serialize=_defaults.LOGURU_SERIALIZE, |
| 252 | backtrace=_defaults.LOGURU_BACKTRACE, |
| 253 | diagnose=_defaults.LOGURU_DIAGNOSE, |
| 254 | enqueue=_defaults.LOGURU_ENQUEUE, |
| 255 | context=_defaults.LOGURU_CONTEXT, |
| 256 | catch=_defaults.LOGURU_CATCH, |
| 257 | **kwargs |
| 258 | ): |
| 259 | r"""Add a handler sending log messages to a sink adequately configured. |
| 260 | |
| 261 | Parameters |
| 262 | ---------- |
| 263 | sink : |file-like object|_, |str|, |Path|, |callable|_, |coroutine function|_ or |Handler| |
| 264 | An object in charge of receiving formatted logging messages and propagating them to an |
| 265 | appropriate endpoint. |
| 266 | level : |int| or |str|, optional |
| 267 | The minimum severity level from which logged messages should be sent to the sink. |
| 268 | format : |str| or |callable|_, optional |
| 269 | The template used to format logged messages before being sent to the sink. |
| 270 | filter : |callable|_, |str| or |dict|, optional |