Exemplo n.º 1
0
    def test_log_level_alias_normalized(self):
        """
        The normalized name of the log level is added to the event dict.
        """
        event_dict = add_log_level(None, "warn", {})

        assert "warning" == event_dict["level"]
Exemplo n.º 2
0
    def test_log_level_added(self):
        """
        The log level is added to the event dict.
        """
        event_dict = add_log_level(None, "error", {})

        assert "error" == event_dict["level"]
Exemplo n.º 3
0
def add_log_severity(logger: logging.Logger, method_name: str,
                     event_dict: EventDict) -> EventDict:
    """Add the log level to the event dict as ``severity``.

    Intended for use as a structlog processor.

    This is the same as `structlog.stdlib.add_log_level` except that it
    uses the ``severity`` key rather than ``level`` for compatibility with
    Google Log Explorer and its automatic processing of structured logs.

    Parameters
    ----------
    logger : `logging.Logger`
        The wrapped logger object.
    method_name : `str`
        The name of the wrapped method (``warning`` or ``error``, for
        example).
    event_dict : `structlog.types.EventDict`
        Current context and current event. This parameter is also modified in
        place, matching the normal behavior of structlog processors.

    Returns
    -------
    event_dict : `structlog.types.EventDict`
        The modified `~structlog.types.EventDict` with the added key.
    """
    severity = add_log_level(logger, method_name, {})["level"]
    event_dict["severity"] = severity
    return event_dict
Exemplo n.º 4
0
 def test_log_level_alias_normalized(self):
     """
     The normalized name of the log level is added to the event dict.
     """
     event_dict = add_log_level(None, 'warn', {})
     assert 'warning' == event_dict['level']
Exemplo n.º 5
0
 def test_log_level_added(self):
     """
     The log level is added to the event dict.
     """
     event_dict = add_log_level(None, 'error', {})
     assert 'error' == event_dict['level']
Exemplo n.º 6
0
 def test_log_level_alias_normalized(self):
     """
     The normalized name of the log level is added to the event dict.
     """
     event_dict = add_log_level(None, 'warn', {})
     assert 'warning' == event_dict['level']
Exemplo n.º 7
0
 def test_log_level_added(self):
     """
     The log level is added to the event dict.
     """
     event_dict = add_log_level(None, 'error', {})
     assert 'error' == event_dict['level']