logging: repeated messages
Peter Otten
__peter__ at web.de
Wed Nov 19 05:38:37 EST 2003
Peter Otten wrote:
> How about (untested):
>
> def log(level, message, data=[]):
> if len(data) == 0:
> logging.basicConfig()
> logger = loggin.getLogger('name')
> hdlr = logging.StreamHandler()
> hdlr.setLevel(logging.WARN)
> logger.addHandler(hdlr)
> data.append(hdlr)
Oops, no need to store the StreamHandler,
if data:
...
data.append(1)
should have the same effect. As you don't use the newly created handler in
subsequent calls, I would recommend to move the code inside the if
statement into another function that is only called once at startup.
Peter
More information about the Python-list
mailing list