def basic_logging(proc_name, log_dir=None):
  """
  Configure logging for the program ``proc_name``:
    - Apply log.conf in the config directory.
    - If DESKTOP_LOGLEVEL environment variable is specified, the root console
      handler (stdout/stderr) is set to that level. If there is no console handler,
      a new one is created.
    - Defining the environment variable DESKTOP_DEBUG is the same as setting
      DESKTOP_LOGLEVEL=DEBUG.

  The ``log_dir`` will replace the %LOG_DIR% in log.conf. If not specified, we look
  for the DESTKOP_LOG_DIR environment variable, and then default to the DEFAULT_LOG_DIR.

  This removes all previously installed logging handlers.
  """
  # Setup log_dir
  if not log_dir:
    log_dir = os.getenv("DESKTOP_LOG_DIR", DEFAULT_LOG_DIR)
  if not os.path.exists(log_dir):
    try:
      os.makedirs(log_dir)
    except __HOLE__, err:
      print >> sys.stderr, 'Failed to create log directory "%s": %s' % (log_dir, err)
      raise err

  # Remember where our log directory is
  global _log_dir
  _log_dir = log_dir

  log_conf = _read_log_conf(proc_name, log_dir)

  if log_conf is not None:
    logging.config.fileConfig(log_conf)
    root_logger = logging.getLogger()
  else:
    # Get rid of any preinstalled/default handlers
    root_logger = logging.getLogger()
    for h in root_logger.handlers:
      root_logger.removeHandler(h)

  # always keep DEBUG at the root, since we'll filter in the
  # handlers themselves - this allows the /logs endpoint
  # to always have all logs.
  root_logger.setLevel(logging.DEBUG)

  # Handle env variables
  env_loglevel = os.getenv("DESKTOP_LOGLEVEL")
  env_debug = os.getenv('DESKTOP_DEBUG')
  if env_debug:
    env_loglevel = 'DEBUG'

  if env_loglevel:
    try:
      lvl = getattr(logging, env_loglevel.upper())
    except AttributeError:
      raise Exception("Invalid log level in DESKTOP_LOGLEVEL: %s" % (env_loglevel,))

    # Set the StreamHandler to the level (create one if necessary)
    handler = _find_console_stream_handler(root_logger)
    if not handler:
      handler = logging.StreamHandler()
      handler.setFormatter(logging.Formatter(LOG_FORMAT, DATE_FORMAT))
      root_logger.addHandler(handler)
    handler.setLevel(lvl)

    # Set all loggers but error.log to the same logging level
    error_handler = logging.getLogger('handler_errorlog')
    for h in root_logger.handlers:
      if isinstance(h, (FileHandler, RotatingFileHandler)) and h != error_handler:
        h.setLevel(lvl)
dataset/ETHPy150Open cloudera/hue/desktop/core/src/desktop/log/__init__.py/basic_logging