[Yum-devel] Syslog issues

James Antill james at fedoraproject.org
Tue Mar 23 22:54:58 UTC 2010


On Mon, 2010-03-22 at 21:50 +0200, Ville Skyttä wrote:
> Hello,
> 
> I looked into making syslog_ident, syslog_facility and syslog_device 
> configurable and documented, but now I think things are pretty broken.  Here's 
> how I understand things at the moment:
> 
> yum uses logging.handlers.SysLogHandler for syslog logging and tries to set 
> ident and facility by invoking syslog.openlog() to set the defaults.  That has 
> no effect because logging.handlers.SysLogHandler doesn't use the syslog module 
> at all, it writes directly to sockets -- the default settings from openlog() 
> apply only to syslog() calls.

 To put it eloquently ... Bugger.

> Now, logging.handlers.SysLogHandler can take the facility in its constructor, 
> but oh joy: it doesn't use the constants from the syslog module, it works with 
> its internal logging.handlers.SysLogHandler.LOG_USER etc constants or its 
> internal string mapping to them ("user" -> LOG_USER etc).  Both are 
> undocumented :P.  It *seems* that one can get from the syslog constants to the 
> SysLogHandler-understood ones with >> 3, e.g. syslog.LOG_USER >> 3 == 
> SysLogHandler.LOG_USER.
> 
> Regarding ident, it seems that SysLogHandler doesn't deal with it at all, it 
> just uses strings.  logginglevels' syslogformatter tries to deal with it, but 
> the formatters are bad because they do strings like "yum: $MESSAGE" or 
> "yum($APP): $MESSAGE" (if setLoggingApp() was used) but AFAIU the messages for 
> raw syslog access like SysLogHandler does them should look e.g. like 
> "$TIMESTAMP $HOSTNAME $IDENT[$PID]: $MESSAGE" per RFC 3164 (ignoring the 
> leading <XXX> for now, that's taken care of by SysLogHandler).

 Yeh, what a big pile of suck.

> Regarding the device, syslog_device works as expected.
> 
> How about fixing/improving things like this:
> 
> 1) Make syslog_device take either a host:port string or a path to a device 
> like it currently does.  Empty string (or None) disables syslog logging, so 
> does a path to a nonexistent file (like currently).  host:port gets split into 
> a tuple so that it can be fed to the SysLogHandler constructor.

 For sure.

> 2) Trust that syslog.LOG_FOO >> 3 yields a facility value with which 
> SysLogHandler does the right thing, and use those in SysLogHandler constructor 
> (i.e. modify _syslog_facility_map to contain these >> 3 ones).

 Yeh, also a no brainer.

> 3a) Apply syslog_ident to the syslog formatter in logginglevels.
> ...or:

 I'm not sure what you mean here, maybe you saw something I didn't ...
but I think we need to create our own logging.Formatter() something
like:

 if ident:
     fmt = logging.Formatter("%s[%%(process)d]: %%(message)s",
                             ident)

...and rely on the fact that syslog will add the time, if we exclude it.
asctime is the only thing logging gives us, and that isn't right, so if
that doesn't work we'll have to override the class and redo emit() :(.

> 3b) Completely ignore syslog_ident, there's already 
> logginglevels.setLoggingApp().
> 
> 4) Fix the syslog formatters to produce strings like "$TIMESTAMP $HOSTNAME 
> $APP[$PID]: $MESSAGE".

 ?

> ...or forget about logging.handlers.SysLogHandler, ditch syslog_device, and 
> use the syslog module directly.

 I bet the reason python doesn't use the syslog module is that it's
process global ... and we'd have the same problems there.



More information about the Yum-devel mailing list