Feature #896
closedAdd support for logging to syslog
100%
Description
This is pretty straight forward.
1. In the init function:
if ( log_flags & LOG_F_SYSLOG )
piboxSyslogInit();
2. In the shutdown function:
if ( log_flags & LOG_F_SYSLOG )
piboxSyslogShutdown();
3. In logger local:
/* ---- SYSLOG OUTPUT ---- */
if ( log_flags & LOG_F_SYSLOG )
{
if ( verbose >= type )
piboxSyslog(type, hdr, LogType[type], buf);
}
4. Add LOG_F_SYSLOG to log.h and the comment in piboxLoggerSetFlags().
5. Then add the following functions:
/*
* These functions are separate from piboxLogger to avoid namespace clashes.
*/
void
piboxSyslogInit()
{
openlog("<appname>", LOG_PID, (LOG_USER | LOG_NOTICE | LOG_FACMASK));
}
void
piboxSyslog( int type, const char *hdr, const char *logtype, const char *buf )
{
syslog(SLOG[type], "%s %s %s", hdr, logtype, buf);
}
void
piboxSyslogShutdown()
{
closelog();
}
The <appname> may require additional init handling to set the name, or we can get it from the cli args.
Updated by Hammel over 1 year ago
- Status changed from New to In Progress
- % Done changed from 0 to 30
Implemented and ready for testing.
To test, build launcher with syslog feature enabled in piboxLogger, then make sure both updated libpibox and launcher opkgs are installed with launcher's logging enabled.
Updated by Hammel over 1 year ago
- % Done changed from 30 to 50
Both piboxd and libpibox are built as opkg and ready to test on hardware.
Updated by Hammel over 1 year ago
The use of extra init and shutdown functions is not required. I've simplified things a bit by just calling openlog() and closelog() in the existing init and shutdown functions.
I've also made the call to syslog() use a prebuild buffer, as per the recommendation in the syslog(3) man page.
This was tested with an updated piboxd server with a new -r option to enable syslog logging. It works mostly, but for some reason syslog drops a message every now and then. Those message are not dropped when logged to console or to file. Not sure what the problem is.
I'm not sure if I'll ever use this option but it might help with debugging field issues over time since we can use log rotations on /var/log/messages (which is where syslog() is writing these messages).
Code tested on hardware, committed and pushed.
Closing issue.
Updated by Hammel over 1 year ago
- Status changed from In Progress to Closed
- % Done changed from 50 to 100