util.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import datetime
  2. import sys
  3. import logging
  4. def init_logging():
  5. # to debug where a log stmt is coming from, add %(pathname)s to the start
  6. logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s',
  7. stream = sys.stdout)
  8. logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARN)
  9. logging.getLogger('test.requests.packages.urllib3.connectionpool').setLevel(logging.WARN)
  10. '''
  11. format:
  12. asctime %(asctime)s Human-readable time when the LogRecord was created. By default this is of the form 2003-07-08 16:49:45,896 (the numbers after the comma are millisecond portion of the time).
  13. created %(created)f Time when the LogRecord was created (as returned by time.time()).
  14. exc_info You shouldn't need to format this yourself. Exception tuple (a la sys.exc_info) or, if no exception has occurred, None.
  15. filename %(filename)s Filename portion of pathname.
  16. funcName %(funcName)s Name of function containing the logging call.
  17. levelname %(levelname)s Text logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL').
  18. levelno %(levelno)s Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL).
  19. lineno %(lineno)d Source line number where the logging call was issued (if available).
  20. module %(module)s Module (name portion of filename).
  21. msecs %(msecs)d Millisecond portion of the time when the LogRecord was created.
  22. message %(message)s The logged message, computed as msg % args. This is set when Formatter.format() is invoked.
  23. msg You shouldn't need to format this yourself. The format string passed in the original logging call. Merged with args to produce message, or an arbitrary object (see Using arbitrary objects as messages).
  24. name %(name)s Name of the logger used to log the call.
  25. pathname %(pathname)s Full pathname of the source file where the logging call was issued (if available).
  26. process %(process)d Process ID (if available).
  27. processName %(processName)s Process name (if available).
  28. relativeCreated %(relativeCreated)d Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded.
  29. thread %(thread)d Thread ID (if available).
  30. threadName %(threadName)s Thread name (if available).
  31. '''
  32. def datetime_from_unix_time(utc_timestamp):
  33. return datetime.datetime.utcfromtimestamp(utc_timestamp)