Revision d21d09d6 lib/utils.py

b/lib/utils.py
1653 1653
  return port
1654 1654

  
1655 1655

  
1656
def SetupLogging(logfile, debug=False, stderr_logging=False, program=""):
1656
def SetupLogging(logfile, debug=False, stderr_logging=False, program="",
1657
                 multithreaded=False):
1657 1658
  """Configures the logging module.
1658 1659

  
1659 1660
  @type logfile: str
......
1665 1666
  @param stderr_logging: whether we should also log to the standard error
1666 1667
  @type program: str
1667 1668
  @param program: the name under which we should log messages
1669
  @type multithreaded: boolean
1670
  @param multithreaded: if True, will add the thread name to the log file
1668 1671
  @raise EnvironmentError: if we can't open the log file and
1669 1672
      stderr logging is disabled
1670 1673

  
1671 1674
  """
1672
  fmt = "%(asctime)s: " + program + " "
1675
  fmt = "%(asctime)s: " + program + " pid=%(process)d"
1676
  if multithreaded:
1677
    fmt += "/%(threadName)s"
1673 1678
  if debug:
1674
    fmt += ("pid=%(process)d/%(threadName)s %(levelname)s"
1675
           " %(module)s:%(lineno)s %(message)s")
1676
  else:
1677
    fmt += "pid=%(process)d %(levelname)s %(message)s"
1679
    fmt += " %(module)s:%(lineno)s"
1680
  fmt += " %(levelname)s %(message)s"
1678 1681
  formatter = logging.Formatter(fmt)
1679 1682

  
1680 1683
  root_logger = logging.getLogger("")
......
1706 1709
    else:
1707 1710
      logfile_handler.setLevel(logging.INFO)
1708 1711
    root_logger.addHandler(logfile_handler)
1709
  except EnvironmentError, err:
1712
  except EnvironmentError:
1710 1713
    if stderr_logging:
1711 1714
      logging.exception("Failed to enable logging to file '%s'", logfile)
1712 1715
    else:

Also available in: Unified diff