[Tutor] Q2: logging not working as expected

jay titleistfour at gmail.com
Fri Nov 16 22:50:48 CET 2007


Dave,

Fix your typo here

> [loggers]
> keys=root,hdk1,hkd2

Should be hkd1 I believe, otherwise the config file is rejected by the
logging module.

> args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)

LOG_USER is not a defined priority by default in syslog, unless it is
something you have custom defined.  I would suggest using one of the
LOCAL[1-6] levels instead.


> logging.config.fileConfig("logging.conf")
> logger = logging.getLogger('hkd1')
> logger.info('Test Messages')

Finally, call using the qualified name 'hkd1'.


It works for me after that...

Although I agree with others, simplification does wonders for debugging.

Jay


On Nov 16, 2007 3:09 PM, dave selby <dave6502 at googlemail.com> wrote:
> I am trying to use the python logging module. At first glance it looks
> pretty complicated but having Ggooled a lot I have come up with a
> trial script of  ...
>
> logging.config.fileConfig("logging.conf")
> logger = logging.getLogger()
> logger.critical("Test Message")
>
> Where 'loggin.conf' contains ...
>
> [loggers]
> keys=root,hdk1,hkd2
>
> [handlers]
> keys=SysLog,hand02
>
> [formatters]
> keys=SysLog
>
> [logger_root]
> level=NOTSET
> handlers=SysLog
>
> [logger_hkd1]
> level=DEBUG
> propagate=1
> qualname=hkd1
> handlers=SysLog
> channel=hkd1
> parent=(root)
>
> [logger_hkd2]
> level=DEBUG
> propagate=1
> qualname=hkd2
> handlers=hand02
> channel=hkd2
> parent=(root)
>
> [handler_hand02]
> class=FileHandler
> level=DEBUG
> formatter=SysLog
> args=('python.log', 'w')
>
> [handler_SysLog]
> class=handlers.SysLogHandler
> level=DEBUG
> formatter=SysLog
> args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
>
> [formatter_SysLog]
> format=%(filename)s[%(process)d]: %(levelname)s: %(message)s
>
> I was trying to get logging to report to Syslog, that failed so I
> changed it to write to a file 'python.log' .  When I execute my test
> script 'python.log' appears but contains no messages and no error
> messages are generated.
>
> Anybody any ideas as to what I am doing wrong ?
>
> Cheers
>
> Dave
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list