[Tutor] Logging module
jay
titleistfour at gmail.com
Wed Jul 25 16:36:24 CEST 2007
Thanks for the reply Kent.
I found the problem. It was rather simple actually. I didn't have remote
logging enabled for syslog. Even though I was logging to localhost, for
some reason, it wouldn't work until I gave syslogd a -r at startup. Thanks
jay
On 7/25/07, Kent Johnson <kent37 at tds.net> wrote:
>
> jay wrote:
> > Hello,
> >
> > I'm trying to setup simple Syslog logging in python using the logging
> > module. I would like to use a config file, but so far haven't been able
> > to get the correct configuration. Actually, I don't get any warnings or
> > errors, program runs fine, but nothing is logged anywhere. I have my
> > syslog LOCAL6 setup to go to /var/log/scripts.log, and that worked fine
> > during testing of the syslog module. But logging gives me more
> > flexibility, I'd rather use that.
> >
> > Anyone with some experience using this module? The documentation, at
> > least to me, is a bit confusing, and I haven't found a good example on
> > the web yet.
>
> I haven't used logging config files, but I don't see anything obviously
> wrong here. A couple of ideas to try:
> - make sure logging.conf can be found by
> print os.path.exists('logging.conf')
> - turn on console logging in the config file and see if that works
> - try to configure the syslog handler in code instead of in a file, then
> translate the successful configuration to a file.
>
> Kent
>
> >
> > ---main.py---
> > #!/usr/bin/env python
> >
> > import logging, logging.config
> >
> > logging.config.fileConfig('logging.conf')
> >
> > log = logging.getLogger()
> > log.info('here we go, testing logger')
> > --- end main.py ---
> >
> > --- logging.conf ---
> > [formatters]
> > keys: detailed,simple
> >
> > [handlers]
> > keys: console,syslog
> >
> > [loggers]
> > keys: root
> >
> > [formatter_simple]
> > format: %(name)s:%(levelname)s: %(message)s
> >
> > [formatter_detailed]
> > format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s
> >
> > [handler_console]
> > class: StreamHandler
> > args: []
> > formatter: simple
> >
> > [handler_syslog]
> > class: handlers.SysLogHandler
> > args: [('localhost', handlers.SYSLOG_UDP_PORT),
> > handlers.SysLogHandler.LOG_LOCAL6 ]
> > formatter: detailed
> >
> > [logger_root]
> > level: INFO
> > handlers: syslog
> >
> > ---- end logging.conf ---
> >
> > Thanks for any help!
> >
> > jay
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070725/4d8abdfd/attachment.html
More information about the Tutor
mailing list