SHARE
TWEET

Untitled

a guest May 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import logging
  2. import logging.handlers
  3. from datetime import datetime
  4.  
  5. from django.conf import settings
  6.  
  7. # Rotate the log file once per week on Sunday (when = W6), and keep 180 days of
  8. # logs (backupCount = 26 weekly files).
  9.  
  10.  
  11. api_logger = logging.getLogger('ApiLogger')
  12. api_logger.addHandler(
  13.     logging.handlers.TimedRotatingFileHandler(settings.LOG_LOCATION + 'api_log', when="W6",
  14.                                               backupCount=26))
  15.  
  16.  
  17. class ApiLogger(object):
  18.     @classmethod
  19.     def log(cls, event):
  20.         api_logger.setLevel(logging.INFO)
  21.         api_logger.info(("%s : %s") % (datetime.now().isoformat(), event))
  22.  
  23.     @classmethod
  24.     def error(cls, event):
  25.         api_logger.setLevel(logging.ERROR)
  26.         api_logger.error(("%s : %s") % (datetime.now().isoformat(), event))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top