Project

General

Profile

Actions

Feature #896

closed

Add support for logging to syslog

Added by Hammel over 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Immediate
Assignee:
Target version:
Start date:
11 Jul 2022
Due date:
% Done:

100%

Estimated time:
Severity:
03 - Medium

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.

Actions #1

Updated by Hammel over 1 year ago

  • Priority changed from High to Immediate
Actions #2

Updated by Hammel over 1 year ago

  • Description updated (diff)
Actions #3

Updated by Hammel over 1 year ago

  • Description updated (diff)
Actions #4

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.

Actions #5

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.

Actions #6

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.

Actions #7

Updated by Hammel over 1 year ago

  • Status changed from In Progress to Closed
  • % Done changed from 50 to 100
Actions

Also available in: Atom PDF