-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
58 lines (47 loc) · 1.58 KB
/
logger.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
Logger
Requires Python 2.7
"""
# Copyright (C) 2011 by
# Sébastien Heymann <[email protected]>
# All rights reserved.
# BSD license.
import logging
#import auxiliary_module
class Logger:
def __init__(self, modulename = ""):
# create logger with 'spam_application'
self.logger = logging.getLogger('visuweb/'+modulename)
self.logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fhd = logging.FileHandler('visuweb-debug.log')
fhd.setLevel(logging.DEBUG)
# create file handler which logs warning messages
fhw = logging.FileHandler('visuweb-warning.log')
fhw.setLevel(logging.WARNING)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s %(name)-22s %(levelname)-10s %(message)s')
fhd.setFormatter(formatter)
fhw.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
self.logger.addHandler(fhd)
self.logger.addHandler(fhw)
self.logger.addHandler(ch)
def get(self):
return self.logger
def info(self, msg, *args, **kwargs):
self.logger.info(msg, *args, **kwargs)
def warn(self, msg, *args, **kwargs):
self.logger.warn(msg, *args, **kwargs)
def error(self, msg, *args, **kwargs):
self.logger.error(msg, *args, **kwargs)
def critical(self, msg, *args, **kwargs):
self.logger.critical(msg, *args, **kwargs)
def exception(self, msg, *args):
self.logger.exception(msg, *args)