Reusable Logging

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#in settings.py

LOG_FILENAME = '/var/log/somefile.log'

logger = logging.getLogger('foo')
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(filename=LOG_FILENAME, maxBytes=1000000000, backupCount=5)
FORMAT = "[ %(asctime)s  %(levelname)s ] %(message)s"
formatter = logging.Formatter(FORMAT)
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)

LOGGER = logger

#to use in apps/modules:
try:
    logging = settings.LOGGERG
except AttributeError:
    import logging

More like this

  1. Twisted protocol for receiving logging module messages over a socket by afternoon 4 years, 8 months ago
  2. Log to syslog by fylb 3 years, 4 months ago
  3. apache authentication via cookies by sean 6 years, 3 months ago
  4. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 11 months ago
  5. create_logger helper by amitu 4 years, 3 months ago

Comments

(Forgotten your password?)