Example One
def filter (self, record): "" "We
custom record filtering logic.
Built-in filtering logic (via logging. Filter) is too limiting.
"" " If not self.filters: return
True
matched = False
rname = record.name # shortcut to
name in self.filters:< C8/>if Rname = = = Name or Rname.startswith (name+ '. '):
matched = True return
matched
Example Two
def _create_log_handlers (stream): "" "Create and return a default list of logging.
Handler instances.
The Format WARNING messages and above to display the logging level and messages strictly below WARNING not to display it.
Args:stream:See the configure_logging () docstring. "" # Handles logging.
WARNING and above. Error_Handler = logging. Streamhandler (Stream) error_handler.setlevel (logging. WARNING) formatter = logging. Formatter ("% (levelname) s:% (message) S") Error_handler.setformatter (Formatter) # Create a logging.
Filter instance that is only accepts messages # below WARNING (i.e. filters out anything WARNING or above). Non_error_filter = logging. Filter () # The filter method accepts a logging.
LogRecord instance. Non_error_filter.filter = Lambda Record:record.levelno < logging. WARNING Non_error_handler = logging. Streamhandler (Stream) Non_error_handler.addfilter (non_error_filter) formatter = logging. Formatter("% (message) S") Non_error_handler.setformatter (formatter) return [Error_Handler, Non_error_handler]
Example Three
def _default_handlers (Stream): "" "return a list of the ' Default logging handlers to use.
Args:stream:See the configure_logging () docstring.
"" # Create the filter. def should_log (record): "" "return whether a logging.
LogRecord should be logged. "" " # fixme:enable The logging of autoinstall messages once # AutoInstall is adjusted. Currently, AutoInstall logs # INFO messages when importing already-downloaded packages, # WH
The ICH is too verbose. If Record.name.startswith ("Webkitpy.thirdparty.autoinstall"): Return False return True Logging_fi Lter = logging.
Filter () Logging_filter.filter = should_log # Create the handler. Handler = logging. Streamhandler (stream) formatter = logging. Formatter ("% (name) s: [% (levelname) s]% (message) S") Handler.setformatter (Formatter) handler.addfilter (logging_filte R) return [handler]