absl.logging.converter module

Module to convert log levels between Abseil Python, C++, and Python standard.

This converter has to convert (best effort) between three different logging level schemes:

cpp = The C++ logging level scheme used in Abseil C++. absl = The absl.logging level scheme used in Abseil Python. standard = The python standard library logging level scheme.

Here is a handy ascii chart for easy mental mapping.

LEVEL | cpp | absl | standard | ———+—–+——–+———-+ DEBUG | 0 | 1 | 10 | INFO | 0 | 0 | 20 | WARNING | 1 | -1 | 30 | ERROR | 2 | -2 | 40 | CRITICAL | 3 | -3 | 50 | FATAL | 3 | -3 | 50 |

Note: standard logging CRITICAL is mapped to absl/cpp FATAL. However, only CRITICAL logs from the absl logger (or absl.logging.fatal) will terminate the program. CRITICAL logs from non-absl loggers are treated as error logs with a message prefix “CRITICAL - “.

Converting from standard to absl or cpp is a lossy conversion. Converting back to standard will lose granularity. For this reason, users should always try to convert to standard, the richest representation, before manipulating the levels, and then only to cpp or absl if those level schemes are absolutely necessary.

absl.logging.converter.absl_to_cpp(level)[source]

Converts an absl log level to a cpp log level.

Parameters

level – int, an absl.logging level.

Raises

TypeError – Raised when level is not an integer.

Returns

The corresponding integer level for use in Abseil C++.

absl.logging.converter.absl_to_standard(level)[source]

Converts an integer level from the absl value to the standard value.

Parameters

level – int, an absl.logging level.

Raises

TypeError – Raised when level is not an integer.

Returns

The corresponding integer level for use in standard logging.

absl.logging.converter.get_initial_for_level(level)[source]

Gets the initial that should start the log line for the given level.

It returns: - ‘I’ when: level < STANDARD_WARNING. - ‘W’ when: STANDARD_WARNING <= level < STANDARD_ERROR. - ‘E’ when: STANDARD_ERROR <= level < STANDARD_CRITICAL. - ‘F’ when: level >= STANDARD_CRITICAL.

Parameters

level – int, a Python standard logging level.

Returns

The first initial as it would be logged by the C++ logging module.

absl.logging.converter.standard_to_absl(level)[source]

Converts an integer level from the standard value to the absl value.

Parameters

level – int, a Python standard logging level.

Raises

TypeError – Raised when level is not an integer.

Returns

The corresponding integer level for use in absl logging.

absl.logging.converter.standard_to_cpp(level)[source]

Converts an integer level from the standard value to the cpp value.

Parameters

level – int, a Python standard logging level.

Raises

TypeError – Raised when level is not an integer.

Returns

The corresponding integer level for use in cpp logging.

absl.logging.converter.string_to_standard(level)[source]

Converts a string level to standard logging level value.

Parameters

level – str, case-insensitive ‘debug’, ‘info’, ‘warning’, ‘error’, ‘fatal’.

Returns

The corresponding integer level for use in standard logging.