B @` @sdZddlmZddlmZddlmZddlZejZejZ ej Z ej Z ejZdZdZdZdZdZd Zed ed ed ed ediZeeeeeedZeeee ee ee eeiZeddeDZddZddZddZddZddZ ddZ!dS)aModule 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. )absolute_import)division)print_functionNFATALERRORWARNINGINFODEBUG)r r r WARNr r ccs|]\}}||fVqdS)N).0kvrr:/tmp/pip-unpacked-wheel-01biqzia/absl/logging/converter.py YsrcCs,|tkr dS|tkrdS|tkr$dSdSdS)aGets 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. Args: level: int, a Python standard logging level. Returns: The first initial as it would be logged by the C++ logging module. IWEFN)STANDARD_WARNINGSTANDARD_ERRORSTANDARD_CRITICAL)levelrrrget_initial_for_level\srcCs2t|tstdt||dkr(dS| SdS)zConverts an absl log level to a cpp log level. Args: 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++. zExpect an int level, found {}rN) isinstanceint TypeErrorformattype)rrrr absl_to_cppus r#cCsDt|tstdt||tkr(t}|tkr8t|St|dS)aConverts an integer level from the absl value to the standard value. Args: 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. zExpect an int level, found {}r) rrr r!r" ABSL_FATAL ABSL_DEBUGABSL_TO_STANDARDSTANDARD_DEBUG)rrrrabsl_to_standards r(cCstt|S)zConverts a string level to standard logging level value. Args: level: str, case-insensitive 'debug', 'info', 'warning', 'error', 'fatal'. Returns: The corresponding integer level for use in standard logging. )r( ABSL_NAMESgetupper)rrrrstring_to_standards r,cCstt|tstdt||dkr(d}|tkr,sL