Example #1
0
def _setup_scribe_logging():
    filter = GenericFilter(lambda r_l: r_l >= LogOptions.scribe_log_level())
    formatter = ProxyFormatter(LogOptions.scribe_log_scheme)
    scribe_handler = ScribeHandler(buffer=LogOptions.scribe_buffer(),
                                   category=LogOptions.scribe_category(),
                                   host=LogOptions.scribe_host(),
                                   port=LogOptions.scribe_port())
    scribe_handler.setFormatter(formatter)
    scribe_handler.addFilter(filter)
    return [scribe_handler]
Example #2
0
def _setup_scribe_logging():
  filter = GenericFilter(lambda r_l: r_l >= LogOptions.scribe_log_level())
  formatter = ProxyFormatter(LogOptions.scribe_log_scheme)
  scribe_handler = ScribeHandler(buffer=LogOptions.scribe_buffer(),
                                 category=LogOptions.scribe_category(),
                                 host=LogOptions.scribe_host(),
                                 port=LogOptions.scribe_port())
  scribe_handler.setFormatter(formatter)
  scribe_handler.addFilter(filter)
  return [scribe_handler]
Example #3
0
def init(filebase=None):
    """
    Sets up default stderr logging and, if filebase is supplied, sets up disk logging using:
      {--log_dir}/filebase.{INFO,WARNING,...}

    If '--log_simple' is specified, logs are written into a single file:
      {--log_dir}/filebase.log
  """
    logging._acquireLock()

    # set up permissive logger
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)

    # clear existing handlers
    teardown_scribe_logging()
    teardown_stderr_logging()
    teardown_disk_logging()
    for handler in root_logger.handlers:
        root_logger.removeHandler(handler)

    # setup INFO...FATAL handlers
    if filebase:
        _initialize_disk_logging()
        initializer = _setup_aggregated_disk_logging if LogOptions.simple(
        ) else _setup_disk_logging
        for handler in initializer(filebase):
            root_logger.addHandler(handler)
            _DISK_LOGGERS.append(handler)

    if LogOptions._is_scribe_logging_required():
        try:
            for handler in _setup_scribe_logging():
                root_logger.addHandler(handler)
                _SCRIBE_LOGGERS.append(handler)
        except ScribeHandler.ScribeHandlerException as err:
            print_stderr(err)

    for handler in _setup_stderr_logging():
        root_logger.addHandler(handler)
        _STDERR_LOGGERS.append(handler)

    logging._releaseLock()

    if len(_DISK_LOGGERS) > 0:
        print_stderr('Writing log files to disk in %s' % LogOptions.log_dir())
    if len(_SCRIBE_LOGGERS) > 0:
        print_stderr('Sending log messages to scribe host=%s:%d category=%s' %
                     (LogOptions.scribe_host(), LogOptions.scribe_port(),
                      LogOptions.scribe_category()))

    return root_logger
Example #4
0
def init(filebase=None):
  """
    Sets up default stderr logging and, if filebase is supplied, sets up disk logging using:
      {--log_dir}/filebase.{INFO,WARNING,...}

    If '--log_simple' is specified, logs are written into a single file:
      {--log_dir}/filebase.log
  """
  logging._acquireLock()

  # set up permissive logger
  root_logger = logging.getLogger()
  root_logger.setLevel(logging.DEBUG)

  # clear existing handlers
  teardown_scribe_logging()
  teardown_stderr_logging()
  teardown_disk_logging()
  for handler in root_logger.handlers:
    root_logger.removeHandler(handler)

  # setup INFO...FATAL handlers
  if filebase:
    _initialize_disk_logging()
    initializer = _setup_aggregated_disk_logging if LogOptions.simple() else _setup_disk_logging
    for handler in initializer(filebase):
      root_logger.addHandler(handler)
      _DISK_LOGGERS.append(handler)

  if LogOptions._is_scribe_logging_required():
    try:
      for handler in _setup_scribe_logging():
        root_logger.addHandler(handler)
        _SCRIBE_LOGGERS.append(handler)
    except ScribeHandler.ScribeHandlerException as err:
      print_stderr(err)

  for handler in _setup_stderr_logging():
    root_logger.addHandler(handler)
    _STDERR_LOGGERS.append(handler)

  logging._releaseLock()

  if len(_DISK_LOGGERS) > 0:
    print_stderr('Writing log files to disk in %s' % LogOptions.log_dir())
  if len(_SCRIBE_LOGGERS) > 0:
    print_stderr('Sending log messages to scribe host=%s:%d category=%s'
          % (LogOptions.scribe_host(), LogOptions.scribe_port(), LogOptions.scribe_category()))

  return root_logger