Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / distutils / log.py
CommitLineData
920dae64
AT
1"""A simple log mechanism styled after PEP 282."""
2
3# This module should be kept compatible with Python 2.1.
4
5# The class here is styled after PEP 282 so that it could later be
6# replaced with a standard Python logging implementation.
7
8DEBUG = 1
9INFO = 2
10WARN = 3
11ERROR = 4
12FATAL = 5
13
14import sys
15
16class Log:
17
18 def __init__(self, threshold=WARN):
19 self.threshold = threshold
20
21 def _log(self, level, msg, args):
22 if level >= self.threshold:
23 print msg % args
24 sys.stdout.flush()
25
26 def log(self, level, msg, *args):
27 self._log(level, msg, args)
28
29 def debug(self, msg, *args):
30 self._log(DEBUG, msg, args)
31
32 def info(self, msg, *args):
33 self._log(INFO, msg, args)
34
35 def warn(self, msg, *args):
36 self._log(WARN, msg, args)
37
38 def error(self, msg, *args):
39 self._log(ERROR, msg, args)
40
41 def fatal(self, msg, *args):
42 self._log(FATAL, msg, args)
43
44_global_log = Log()
45log = _global_log.log
46debug = _global_log.debug
47info = _global_log.info
48warn = _global_log.warn
49error = _global_log.error
50fatal = _global_log.fatal
51
52def set_threshold(level):
53 # return the old threshold for use from tests
54 old = _global_log.threshold
55 _global_log.threshold = level
56 return old
57
58def set_verbosity(v):
59 if v <= 0:
60 set_threshold(WARN)
61 elif v == 1:
62 set_threshold(INFO)
63 elif v >= 2:
64 set_threshold(DEBUG)