def ConfigureLogging(debug_level=logging.INFO,
                     show_level=True,
                     stderr=True,
                     syslog=True,
                     facility=None):
  """Sets up logging defaults for the root logger.

  LaunchDaemons should use syslog and disable stderr (or send it to /dev/null in
  the launchd plist). This ensures that multi-line logs (such as those from
  logging.exception) are not split and we don't get dups.

  Other programs should use both stderr and syslog (the default).

  Possible syslog facility names come from
  logging.handlers.SysLogHandler.facility_names.keys():
  ['ftp', 'daemon', 'uucp', 'security', 'local7', 'local4', 'lpr', 'auth',
   'local0', 'cron', 'syslog', 'user', 'mail', 'local5', 'kern', 'news',
   'local6', 'local1', 'authpriv', 'local3', 'local2']

  Args:
    debug_level: python logging level
    show_level: show the logging level in the message for stderr
    stderr: If true, log to stderr
    syslog: If true log to syslog
    facility: string, syslog facility to use
  Raises:
    LogConfigurationError: if no handers are set
  """
  if not stderr and not syslog:
    raise LogConfigurationError('Neither syslog nor stdout handlers set.')

  if facility and not syslog:
    raise LogConfigurationError('facility can only be used with syslog.')

  logger = logging.getLogger()

  # Clear any existing handlers
  logger.handlers = []

  logger.setLevel(debug_level)
  if syslog:
    # Get the default syslog facility
    facility_id = logging.handlers.SysLogHandler.LOG_USER
    if facility:
      try:
        facility_id = logging.handlers.SysLogHandler.facility_names[facility]
      except __HOLE__:
        logging.error('%s is an invalid facility, using default.', facility)
    try:
      syslog_handler = MultilineSysLogHandler(facility=facility_id)
      _ConfigureHandler(syslog_handler, logger, LOG_FORMAT_SYSLOG, debug_level)
    except socket.error:
      print >>sys.stderr, 'Warning: Could not configure syslog based logging.'
      stderr = True

  if stderr:
    stderr_handler = logging.StreamHandler()
    if show_level:
      _ConfigureHandler(stderr_handler, logger, LOG_FORMAT_STDERR_LEVEL,
                        debug_level)
    else:
      _ConfigureHandler(stderr_handler, logger, LOG_FORMAT_STDERR, debug_level)

  logging.debug('Logging enabled at level %s', debug_level)
dataset/ETHPy150Open google/macops/gmacpyutil/gmacpyutil/gmacpyutil.py/ConfigureLogging