File: syslog.c

package info (click to toggle)
swupdate 2025.12%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,004 kB
  • sloc: ansic: 66,621; python: 6,291; makefile: 791; sh: 538; javascript: 229
file content (53 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * (C) Copyright 2016
 * Denis Osterland, Diehl Connectivity Solutions GmbH, Denis.Osterland@diehl.com.
 *
 * SPDX-License-Identifier:     GPL-2.0-only
 */
#include <syslog.h>
#include <stdio.h>
#include "util.h"

static void syslog_notifier(RECOVERY_STATUS status, int error, int level, const char *msg);

int syslog_init(void)
{
   setlogmask(LOG_UPTO(LOG_DEBUG));
   return register_notifier(syslog_notifier);
}

void syslog_notifier(RECOVERY_STATUS status, int error, int level, const char *msg)
{
   const char* statusMsg;

   switch(status) {
      case IDLE: statusMsg = "IDLE"; break;
      case DOWNLOAD: statusMsg = "DOWNLOAD"; break;
      case START: statusMsg = "START"; break;
      case RUN: statusMsg = "RUN"; break;
      case SUCCESS: statusMsg = "SUCCESS"; break;
      case FAILURE: statusMsg = "FAILURE"; break;
      case DONE: statusMsg = "DONE"; break;
      /*
       * Unknown messages are maybe for other subsystems
       * and not to the logger, so silently ignore them
       */
      default: return;
   }

   openlog("swupdate", 0, LOG_USER);

   int logprio = LOG_INFO;
   switch (level) {
      case ERRORLEVEL: logprio = LOG_ERR; break;
      case WARNLEVEL:  logprio = LOG_WARNING; break;
      case INFOLEVEL:  logprio = LOG_INFO; break;
      case DEBUGLEVEL:
      case TRACELEVEL: logprio = LOG_DEBUG; break;
   }

   syslog(logprio, "%s%s %s\n", ((error != (int)RECOVERY_NO_ERROR) ? "FATAL_" : ""), statusMsg, msg);

   closelog();
}