1 """A simple log mechanism styled after PEP 282."""
3 # This module should be kept compatible with Python 2.1.
5 # The class here is styled after PEP 282 so that it could later be
6 # replaced with a standard Python logging implementation.
18 def __init__(self
, threshold
=WARN
):
19 self
.threshold
= threshold
21 def _log(self
, level
, msg
, args
):
22 if level
>= self
.threshold
:
24 # msg may contain a '%'. If args is empty,
25 # don't even try to string-format
31 def log(self
, level
, msg
, *args
):
32 self
._log
(level
, msg
, args
)
34 def debug(self
, msg
, *args
):
35 self
._log
(DEBUG
, msg
, args
)
37 def info(self
, msg
, *args
):
38 self
._log
(INFO
, msg
, args
)
40 def warn(self
, msg
, *args
):
41 self
._log
(WARN
, msg
, args
)
43 def error(self
, msg
, *args
):
44 self
._log
(ERROR
, msg
, args
)
46 def fatal(self
, msg
, *args
):
47 self
._log
(FATAL
, msg
, args
)
51 debug
= _global_log
.debug
52 info
= _global_log
.info
53 warn
= _global_log
.warn
54 error
= _global_log
.error
55 fatal
= _global_log
.fatal
57 def set_threshold(level
):
58 # return the old threshold for use from tests
59 old
= _global_log
.threshold
60 _global_log
.threshold
= level