Log to syslog

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
from logging.handlers import SysLogHandler
from django.conf import settings
from sys import stdout

LOG_AREA_PAYMENT = 'payment'

payment_logger = logging.getLogger(LOG_AREA_PAYMENT)

def init_logging():
    global manage_logger, payment_logger
    """ Initialize the different loggers used in the application """
    # create formatter
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    # default log
    stdoutHandler = logging.StreamHandler(stdout)
    stdoutHandler.setLevel(logging.DEBUG)
    stdoutHandler.setFormatter(formatter)
    logging.getLogger().addHandler(stdoutHandler)
    default_log_handler = SysLogHandler("/dev/log", "local0")
    default_log_handler.setLevel(logging.DEBUG)
    default_log_handler.setFormatter(formatter)
    logging.getLogger().addHandler(default_log_handler)
    
    # payment log
    payment_logger = logging.getLogger(LOG_AREA_PAYMENT)
    payment_logger.setLevel(logging.DEBUG)
    payment_handler = SysLogHandler("/dev/log", "local1")
    payment_handler.setFormatter(formatter)
    payment_logger.addHandler(payment_handler)

logInitDone = False

if not logInitDone:
    logInitDone = True
    init_logging()

More like this

  1. Extended logging module by onlinehero 4 years, 9 months ago
  2. Django app WSGI by ofalk 4 years, 10 months ago
  3. showing environment variables in the django admin by tonemcd 4 years, 2 months ago
  4. MODPYTHON Sample Site Logging by adroffner 5 years, 8 months ago
  5. Middleware that fixes URLs generation for admin and {% url %} for SCGI and WSGI by dottedmag 6 years, 9 months ago

Comments

(Forgotten your password?)