MCPcopy
hub / github.com/Delgan/loguru / level

Method level

loguru/_logger.py:1535–1636  ·  view source on GitHub ↗

r"""Add, update or retrieve a logging level. Logging levels are defined by their ``name`` to which a severity ``no``, an ansi ``color`` tag and an ``icon`` are associated and possibly modified at run-time. To |log| to a custom level, you should necessarily use its name, the

(self, name, no=None, color=None, icon=None)

Source from the content-addressed store, hash-verified

1533 return Logger(self._core, *options, [*patchers, patcher], extra)
1534
1535 def level(self, name, no=None, color=None, icon=None):
1536 r"""Add, update or retrieve a logging level.
1537
1538 Logging levels are defined by their ``name`` to which a severity ``no``, an ansi ``color``
1539 tag and an ``icon`` are associated and possibly modified at run-time. To |log| to a custom
1540 level, you should necessarily use its name, the severity number is not linked back to levels
1541 name (this implies that several levels can share the same severity).
1542
1543 To add a new level, its ``name`` and its ``no`` are required. A ``color`` and an ``icon``
1544 can also be specified or will be empty by default.
1545
1546 To update an existing level, pass its ``name`` with the parameters to be changed. It is not
1547 possible to modify the ``no`` of a level once it has been added.
1548
1549 To retrieve level information, the ``name`` solely suffices.
1550
1551 Parameters
1552 ----------
1553 name : |str|
1554 The name of the logging level.
1555 no : |int|
1556 The severity of the level to be added or updated.
1557 color : |str|
1558 The color markup of the level to be added or updated.
1559 icon : |str|
1560 The icon of the level to be added or updated.
1561
1562 Returns
1563 -------
1564 ``Level``
1565 A |namedtuple| containing information about the level.
1566
1567 Raises
1568 ------
1569 ValueError
1570 If attempting to access a level with a ``name`` that is not registered, or if trying to
1571 change the severity ``no`` of an existing level.
1572
1573 Examples
1574 --------
1575 >>> level = logger.level("ERROR")
1576 >>> print(level)
1577 Level(name='ERROR', no=40, color='<red><bold>', icon='❌')
1578 >>> logger.add(sys.stderr, format="{level.no} {level.icon} {message}")
1579 1
1580 >>> logger.level("CUSTOM", no=15, color="<blue>", icon="@")
1581 Level(name='CUSTOM', no=15, color='<blue>', icon='@')
1582 >>> logger.log("CUSTOM", "Logging...")
1583 15 @ Logging...
1584 >>> logger.level("WARNING", icon=r"/!\\")
1585 Level(name='WARNING', no=30, color='<yellow><bold>', icon='/!\\\\')
1586 >>> logger.warning("Updated!")
1587 30 /!\\ Updated!
1588 """
1589 if not isinstance(name, str):
1590 raise TypeError(
1591 "Invalid level name, it should be a string, not: '%s'" % type(name).__name__
1592 )

Callers 15

addMethod · 0.95
configureMethod · 0.95
test_colors_with_levelFunction · 0.80
test_bind_and_add_levelFunction · 0.80
emitMethod · 0.80
test_level_exists_customFunction · 0.80
test_add_levelFunction · 0.80

Calls 2

ansifyMethod · 0.80
update_formatMethod · 0.80