summaryrefslogtreecommitdiff
path: root/logger.py
blob: 6fd8171fa2d076f2a6ed3a76e685e897402b0458 (plain)
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
37
38
39
import cherrypy
import inspect
import cfg

cherrypy.log.error_file = cfg.status_log_file
cherrypy.log.access_file = cfg.access_log_file
cherrypy.log.screen = False

class Logger():
    """By convention, log levels are DEBUG, INFO, WARNING, ERROR and CRITICAL."""
    def log(self, msg, level="DEBUG"):
        try:
            username = cherrypy.session.get(cfg.session_key)
        except AttributeError:
            username = ''
        cherrypy.log.error("%s %s %s" % (username, level, msg), inspect.stack()[2][3], 20)
    def __call__(self, *args):
        self.log(*args)

    def debug(self, msg):
        self.log(msg)

    def info(self, msg):
        self.log(msg, "INFO")

    def warn(self, msg):
        self.log(msg, "WARNING")

    def warning(self, msg):
        self.log(msg, "WARNING")

    def error(self, msg):
        self.log(msg, "ERROR")

    def err(self, msg):
        self.error(msg)

    def critical(self, msg):
        self.log(msg, "CRITICAL")