summaryrefslogtreecommitdiff
path: root/syslogd/main.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-06-17 16:48:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-06-17 18:20:53 +0200
commit9878e69ebe5b18676f8f5e26ef57d2e47b02e44d (patch)
tree0205ed51f570e2db855fb34b51fe3e7d5a806b9d /syslogd/main.c
parent8a8f49a501fd109bcb722afff7eb2c7852a04107 (diff)
usyslogd: store logs in subdirectory based on service identifier
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'syslogd/main.c')
-rw-r--r--syslogd/main.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/syslogd/main.c b/syslogd/main.c
index 79d6325..263c87d 100644
--- a/syslogd/main.c
+++ b/syslogd/main.c
@@ -134,12 +134,16 @@ static int print_to_log(const syslog_msg_t *msg)
return -1;
for (log = logfiles; log != NULL; log = log->next) {
- if (log->facility == msg->facility)
+ if (log->facility != msg->facility)
+ continue;
+ if (msg->ident == NULL && log->ident[0] == '\0')
+ break;
+ if (msg->ident != NULL && strcmp(msg->ident, log->ident) == 0)
break;
}
if (log == NULL) {
- log = logfile_create(fac_name, msg->facility);
+ log = logfile_create(msg->ident, fac_name, msg->facility);
if (log == NULL)
return -1;
log->next = logfiles;
@@ -149,8 +153,7 @@ static int print_to_log(const syslog_msg_t *msg)
gmtime_r(&msg->timestamp, &tm);
strftime(timebuf, sizeof(timebuf), "%FT%T", &tm);
- logfile_write(log, "[%s][%s][%s][%u] %s", timebuf, lvl_str,
- msg->ident ? msg->ident : "", msg->pid,
+ logfile_write(log, "[%s][%s][%u] %s", timebuf, lvl_str, msg->pid,
msg->message);
return 0;
}