• Home
  • Raw
  • Download

Lines Matching full:logging

15 """Abseil Python logging module implemented on top of standard logging.
19 from absl import logging
21 logging.info('Interesting Stuff')
22 logging.info('Interesting Stuff with Arguments: %d', 42)
24 logging.set_verbosity(logging.INFO)
25 logging.log(logging.DEBUG, 'This will *not* be printed')
26 logging.set_verbosity(logging.DEBUG)
27 logging.log(logging.DEBUG, 'This will be printed')
29 logging.warning('Worrying Stuff')
30 logging.error('Alarming Stuff')
31 logging.fatal('AAAAHHHHH!!!!') # Process exits.
34 Instead, let the logging module perform argument interpolation.
39 logging.info('Interesting Stuff: %s')
41 does not raise an exception because logging.info() has only one
49 logging.debug('Thing: %s', thing.ExpensiveOp())
54 if logging.level_debug():
55 logging.debug('Thing: %s', thing.ExpensiveOp())
57 Per file level logging is supported by logging.vlog() and
58 logging.vlog_is_on(). For example::
60 if logging.vlog_is_on(2):
61 logging.vlog(2, very_expensive_debug_message())
71 Standard logging module defines fatal as an alias to critical, but it's not
84 import logging
99 from absl.logging import converter
110 # Logging levels.
128 # Mask to convert integer thread ids to unsigned quantities for logging purposes
138 # Used by findCaller to skip callers from */logging/__init__.py.
139 _LOGGING_FILE_PREFIX = os.path.join('logging', '__init__.')
183 """Updates absl logging levels to the current verbosity.
194 standard_verbosity = logging.DEBUG - (self._value - 1)
197 if _absl_handler in logging.root.handlers:
199 # a non-NOTSET value if logging.set_verbosity() is called at import time.
200 _absl_logger.setLevel(logging.NOTSET)
201 logging.root.setLevel(standard_verbosity)
232 logging.getLogger(name).setLevel(level)
310 'Logging verbosity level. Messages logged at this level or lower will '
311 'be included. Set to 1 for debug logging. If the flag was not set or '
320 '`logging.getLogger()`, and `level` is a level name (INFO, DEBUG, '
335 'and python logging is used.')
339 """Returns the logging verbosity."""
344 """Sets the logging verbosity.
367 logging.DEBUG|INFO|WARNING|ERROR|FATAL.
378 'set_stderrthreshold only accepts integer absl logging level '
448 level: int, the absl logging level at which to log.
492 the last logging call from the same call site (file + line). Not thread-safe.
495 level: int, the absl logging level at which to log.
497 n_seconds: float or int, seconds which should elapse before logging again.
510 level: int, the absl logging level at which to log.
526 """Logs ``msg % args`` at absl logging level ``level``.
531 level: int, the absl logging level at which to log the message
532 (logging.DEBUG|INFO|WARNING|ERROR|FATAL). While some C++ verbose logging
534 logging.vlog() calls for such purpose.
542 # should use logging.vlog instead for such cases.
550 # Match standard logging's behavior. Before use_absl_handler() and
551 # logging is configured, there is no handler attached on _absl_logger nor
552 # logging.root. So logs go no where.
553 if not logging.root.handlers:
554 logging.basicConfig()
563 level: int, the C++ verbose logging level at which to log the message,
565 callers should prefer logging.log|debug|info|... calls for such purpose.
577 level: int, the C++ verbose logging level at which to log the message,
583 True if logging is turned on for that level.
588 # should use logging.vlog instead for such cases.
604 """Returns True if debug logging is turned on."""
609 """Returns True if info logging is turned on."""
614 """Returns True if warning logging is turned on."""
622 """Returns True if error logging is turned on."""
629 For Python logging, only one file is used and level is ignored. And it returns
634 level: int, the absl.logging level.
640 raise ValueError('Invalid absl.logging level {}'.format(level))
659 is as described in the example. In python standard logging mode,
720 # behavior of the same flag in logging.cc).
737 record: logging.LogRecord, the record to get prefix for.
747 level = logging.ERROR
766 """Skips reporting the prefix of a given function or name by :class:`~absl.logging.ABSLLogger`.
769 :meth:`~absl.logging.ABSLLogger.register_frame_to_skip`.
805 return (log_record.levelno >= logging.FATAL and
810 return (log_record.levelno >= logging.FATAL and
818 class PythonHandler(logging.StreamHandler):
819 """The handler class used by Abseil Python logging implementation."""
826 """Starts logging messages to files instead of standard error."""
879 record: logging.LogRecord, the record to log.
881 # emit() is protected by a lock in logging.Handler, so we don't need to
899 record: :class:`logging.LogRecord`, the record to emit.
901 # People occasionally call logging functions at import time before
912 'WARNING: Logging before flag parsing goes to stderr.\n')
953 class ABSLHandler(logging.Handler):
954 """Abseil Python logging module's log handler."""
989 """Uses the Python logging handler as the current logging handler."""
999 class PythonFormatter(logging.Formatter):
1000 """Formatter class used by :class:`~absl.logging.PythonHandler`."""
1006 record: logging.LogRecord, the record to be formatted.
1013 record.levelno == logging.INFO and
1021 class ABSLLogger(logging.getLoggerClass()):
1058 # Use sys._getframe(2) instead of logging.currentframe(), it's slightly
1079 self.log(logging.CRITICAL, msg, *args, **kwargs)
1083 self.log(logging.FATAL, msg, *args, **kwargs)
1087 self.log(logging.ERROR, msg, *args, **kwargs)
1093 self.log(logging.WARN, msg, *args, **kwargs)
1097 self.log(logging.WARNING, msg, *args, **kwargs)
1101 self.log(logging.INFO, msg, *args, **kwargs)
1105 self.log(logging.DEBUG, msg, *args, **kwargs)
1113 level: int, the standard logging level at which to log the message.
1118 if level >= logging.FATAL:
1129 Non-root loggers are set to disabled after setup with :func:`logging.config`
1130 if it's not explicitly specified. Historically, absl logging will not be
1138 record: logging.LogRecord, the record to handle.
1147 The :class:`~absl.logging.ABSLLogger` sometimes skips method calls on the
1166 """Gets id of current thread, suitable for logging as an unsigned quantity.
1169 consistent with C++ logging. Otherwise, returns the numeric thread id.
1190 """Uses the python implementation of the logging code.
1193 quiet: No logging message about switching logging type.
1197 info('Restoring pure python logging')
1204 """Uses the ABSL logging handler for logging.
1211 # The absl handler logs to stderr by default. To prevent double logging to
1214 # logging.info/debug is called before calling use_absl_handler().
1216 h for h in logging.root.handlers
1217 if isinstance(h, logging.StreamHandler) and h.stream == sys.stderr]
1219 logging.root.removeHandler(h)
1223 if absl_handler not in logging.root.handlers:
1224 logging.root.addHandler(absl_handler)
1236 original_logger_class = logging.getLoggerClass()
1237 logging.setLoggerClass(ABSLLogger)
1238 _absl_logger = logging.getLogger('absl')
1239 logging.setLoggerClass(original_logger_class)