r"""Parametrize a logging call to slightly change generated log message. Note that it's not possible to chain |opt| calls, the last one takes precedence over the others as it will "reset" the options to their default values. Parameters ---------- exception :
(
self,
*,
exception=None,
record=False,
lazy=False,
colors=False,
raw=False,
capture=True,
depth=0,
ansi=False
)
| 1303 | return Catcher(False) |
| 1304 | |
| 1305 | def opt( |
| 1306 | self, |
| 1307 | *, |
| 1308 | exception=None, |
| 1309 | record=False, |
| 1310 | lazy=False, |
| 1311 | colors=False, |
| 1312 | raw=False, |
| 1313 | capture=True, |
| 1314 | depth=0, |
| 1315 | ansi=False |
| 1316 | ): |
| 1317 | r"""Parametrize a logging call to slightly change generated log message. |
| 1318 | |
| 1319 | Note that it's not possible to chain |opt| calls, the last one takes precedence over the |
| 1320 | others as it will "reset" the options to their default values. |
| 1321 | |
| 1322 | Parameters |
| 1323 | ---------- |
| 1324 | exception : |bool|, |tuple| or |Exception|, optional |
| 1325 | If it does not evaluate as ``False``, the passed exception is formatted and added to the |
| 1326 | log message. It could be an |Exception| object or a ``(type, value, traceback)`` tuple, |
| 1327 | otherwise the exception information is retrieved from |sys.exc_info|. |
| 1328 | record : |bool|, optional |
| 1329 | If ``True``, the record dict contextualizing the logging call can be used to format the |
| 1330 | message by using ``{record[key]}`` in the log message. |
| 1331 | lazy : |bool|, optional |
| 1332 | If ``True``, the logging call attribute to format the message should be functions which |
| 1333 | will be called only if the level is high enough. This can be used to avoid expensive |
| 1334 | functions if not necessary. |
| 1335 | colors : |bool|, optional |
| 1336 | If ``True``, logged message will be colorized according to the markups it possibly |
| 1337 | contains. |
| 1338 | raw : |bool|, optional |
| 1339 | If ``True``, the formatting of each sink will be bypassed and the message will be sent |
| 1340 | as is. |
| 1341 | capture : |bool|, optional |
| 1342 | If ``False``, the ``**kwargs`` of logged message will not automatically populate |
| 1343 | the ``extra`` dict (although they are still used for formatting). |
| 1344 | depth : |int|, optional |
| 1345 | Specify which stacktrace should be used to contextualize the logged message. This is |
| 1346 | useful while using the logger from inside a wrapped function to retrieve worthwhile |
| 1347 | information. |
| 1348 | ansi : |bool|, optional |
| 1349 | Deprecated since version 0.4.1: the ``ansi`` parameter will be removed in Loguru 1.0.0, |
| 1350 | it is replaced by ``colors`` which is a more appropriate name. |
| 1351 | |
| 1352 | Returns |
| 1353 | ------- |
| 1354 | :class:`~Logger` |
| 1355 | A logger wrapping the core logger, but transforming logged message adequately before |
| 1356 | sending. |
| 1357 | |
| 1358 | Examples |
| 1359 | -------- |
| 1360 | >>> try: |
| 1361 | ... 1 / 0 |
| 1362 | ... except ZeroDivisionError: |