Custom log handler and logging.config.fileConfig()

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu May 29 13:28:24 EDT 2008


On 29 May, 15:53, "Lowell Alleman" <low... at allemansonline.com> wrote:
> Is there any reason not to do this assignment in the "myhandler.py"
> directly?  This would save a step for each application that needs to
> use it.
>
> Starting from your example, it would now look like this:
>
> # -- myhandler.py ---
> importlogging.handlers
>
> class MySpecialHandler(logging.handlers.RotatingFileHandler):
>     def __init__(self, fn):
>        logging.handlers.RotatingFileHandler.__init__(self, fn,
>            maxBytes=2000, backupCount=3)
>
> # Register handler in the "logging.handlers" namespacelogging.handlers.MySpecialHandler = MySpecialHandler
>
> # -- app.py ---
> importlogging.handlers,logging.config
> import myhandler
>
> logging.config.fileConfig("logging.ini")
> ...

Doing it the way you suggest should be fine.

Regards,

Vinay Sajip



More information about the Python-list mailing list