1 """A simple log mechanism styled after PEP 282."""
3 # The class here is styled after PEP 282 so that it could later be
4 # replaced with a standard Python logging implementation.
16 def __init__(self
, threshold
=WARN
):
17 self
.threshold
= threshold
19 def _log(self
, level
, msg
, args
):
20 if level
>= self
.threshold
:
22 # msg may contain a '%'. If args is empty,
23 # don't even try to string-format
29 def log(self
, level
, msg
, *args
):
30 self
._log
(level
, msg
, args
)
32 def debug(self
, msg
, *args
):
33 self
._log
(DEBUG
, msg
, args
)
35 def info(self
, msg
, *args
):
36 self
._log
(INFO
, msg
, args
)
38 def warn(self
, msg
, *args
):
39 self
._log
(WARN
, msg
, args
)
41 def error(self
, msg
, *args
):
42 self
._log
(ERROR
, msg
, args
)
44 def fatal(self
, msg
, *args
):
45 self
._log
(FATAL
, msg
, args
)
49 debug
= _global_log
.debug
50 info
= _global_log
.info
51 warn
= _global_log
.warn
52 error
= _global_log
.error
53 fatal
= _global_log
.fatal
55 def set_threshold(level
):
56 # return the old threshold for use from tests
57 old
= _global_log
.threshold
58 _global_log
.threshold
= level