Skip to content

Commit

Permalink
feat: syslog message add priority
Browse files Browse the repository at this point in the history
  • Loading branch information
eeff committed Nov 22, 2023
1 parent 7d671ea commit e2067bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ file perms = 666

stdout_format = "%d:%ms [%V] [%c] %f:%L %m%n"
file_format = "%d:%ms [%V] %f:%L %m%n"
syslog = "%d:%ms %H neuron[%p]: [%V] [%c] %f:%L %m%n"
syslog = "<P>%d:%ms %H neuron[%p]: [%V] [%c] %f:%L %m%n"

[rules]

*.* "./logs/%c.log", 25MB * 1 ~ "./logs/%c.#2r.log"; file_format
*.* >stdout; stdout_format
*.* $remote_syslog; syslog
*.* $remote_syslog,"%V"; syslog
23 changes: 23 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,31 @@ static void sig_handler(int sig)
exit(-1);
}

static inline char syslog_priority(const char *level)
{
switch (level[0]) {
case 'D': // DEBUG
return '7';
case 'I': // INFO
return '6';
case 'N': // NOTICE
return '5';
case 'W': // WARN
return '4';
case 'E': // ERROR
return '3';
case 'F': // FATAL
return '2';
default: // UNKNOWN
return '1';
}
}

static int remote_syslog(zlog_msg_t *msg)
{
// fix priority
msg->buf[1] = syslog_priority(msg->path);

sendto(g_remote_syslog_ctx.fd, msg->buf, msg->len, 0,
(const struct sockaddr *) &g_remote_syslog_ctx.addr,
sizeof(g_remote_syslog_ctx.addr));
Expand Down
4 changes: 2 additions & 2 deletions zlog.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ file perms = 666
[formats]

simple = "%d:%ms [%V] %f:%L %m%n"
syslog = "%d:%ms %H neuron[%p]: [%V] [%c] %f:%L %m%n"
syslog = "<P>%d:%ms %H neuron[%p]: [%V] [%c] %f:%L %m%n"

[rules]

*.* "./logs/%c.log", 25MB * 1 ~ "./logs/%c.#2r.log"; simple
*.* $remote_syslog; syslog
*.* $remote_syslog,"%V"; syslog

0 comments on commit e2067bf

Please sign in to comment.