forked from sbabic/swupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyslog.c
53 lines (44 loc) · 1.45 KB
/
syslog.c
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
/*
* (C) Copyright 2016
* Denis Osterland, Diehl Connectivity Solutions GmbH, [email protected].
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#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();
}