Merge pull request #1689 from eeff/eeff/dev

feat: syslog message add priority
This commit is contained in:
fengzeroz
2023-11-23 09:55:24 +08:00
committed by GitHub
3 changed files with 27 additions and 4 deletions
+2 -2
View File
@@ -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
View File
@@ -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));
+2 -2
View File
@@ -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