uploading works, but AV info is not automatically detected and video activation featu...
[living-lab-site.git] / cis / logger.py
1 import sys
2
3 LOG_LEVEL_ALL = 0
4 LOG_LEVEL_DEBUG = 1
5 LOG_LEVEL_INFO = 2
6 LOG_LEVEL_WARNING = 3
7 LOG_LEVEL_ERROR = 4
8 LOG_LEVEL_FATAL = 5
9 LOG_LEVEL_OFF = 6
10
11 LOG_LEVEL_NAMES = { \
12     LOG_LEVEL_DEBUG: 'DEBUG', \
13     LOG_LEVEL_INFO: 'INFO', \
14     LOG_LEVEL_WARNING: 'WARNING', \
15     LOG_LEVEL_ERROR: 'ERROR', \
16     LOG_LEVEL_FATAL: 'FATAL', \
17 }
18
19 import config
20
21 def log_msg(msg, level=LOG_LEVEL_INFO):
22     """
23     Prints log messages based on the log level.
24     """
25     
26     if level == LOG_LEVEL_ALL or level == LOG_LEVEL_OFF:
27         return
28         
29     if level < config.LOG_LEVEL:
30         return
31     
32     if level >= LOG_LEVEL_ERROR:
33         f = sys.stderr
34     else:
35         f = sys.stdout
36         
37     f.write('[%s] %s\n' % (LOG_LEVEL_NAMES[level], msg))