mirror of https://git.kore.io/kore.git
Use a more structured log format.
This commit is contained in:
parent
5dcf3d1550
commit
0de5d5e4c7
|
@ -885,6 +885,10 @@ void kore_connection_check_idletimer(u_int64_t,
|
||||||
struct connection *);
|
struct connection *);
|
||||||
int kore_connection_accept(struct listener *,
|
int kore_connection_accept(struct listener *,
|
||||||
struct connection **);
|
struct connection **);
|
||||||
|
void kore_connection_log(struct connection *,
|
||||||
|
const char *, ...)
|
||||||
|
__attribute__((format (printf, 2, 3)));
|
||||||
|
const char *kore_connection_ip(struct connection *);
|
||||||
|
|
||||||
void kore_log_init(void);
|
void kore_log_init(void);
|
||||||
void kore_log_file(const char *);
|
void kore_log_file(const char *);
|
||||||
|
|
|
@ -399,3 +399,52 @@ kore_connection_nonblock(int fd, int nodelay)
|
||||||
|
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kore_connection_log(struct connection *c, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
struct kore_buf buf;
|
||||||
|
va_list args;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
kore_buf_init(&buf, 128);
|
||||||
|
kore_buf_appendf(&buf, "ip=[%s] msg=[", kore_connection_ip(c));
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
kore_buf_appendv(&buf, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
kore_buf_appendf(&buf, "]");
|
||||||
|
|
||||||
|
ptr = kore_buf_stringify(&buf, NULL);
|
||||||
|
kore_log(LOG_NOTICE, "%s", ptr);
|
||||||
|
kore_free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
kore_connection_ip(struct connection *c)
|
||||||
|
{
|
||||||
|
static char addr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
|
memset(addr, 0, sizeof(addr));
|
||||||
|
|
||||||
|
switch (c->family) {
|
||||||
|
case AF_INET:
|
||||||
|
if (inet_ntop(c->family,
|
||||||
|
&(c->addr.ipv4.sin_addr), addr, sizeof(addr)) == NULL)
|
||||||
|
fatal("inet_ntop: %s", errno_s);
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
if (inet_ntop(c->family,
|
||||||
|
&(c->addr.ipv6.sin6_addr), addr, sizeof(addr)) == NULL)
|
||||||
|
fatal("inet_ntop: %s", errno_s);
|
||||||
|
break;
|
||||||
|
case AF_UNIX:
|
||||||
|
(void)kore_strlcpy(addr, "unix-socket", sizeof(addr));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fatal("unknown family %d", c->family);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (addr);
|
||||||
|
}
|
||||||
|
|
|
@ -95,9 +95,9 @@ kore_log(int prio, const char *fmt, ...)
|
||||||
str = kore_buf_stringify(&buf, NULL);
|
str = kore_buf_stringify(&buf, NULL);
|
||||||
|
|
||||||
if (kore_foreground || fp != stdout)
|
if (kore_foreground || fp != stdout)
|
||||||
log_print(prio, "[parent]: %s\n", str);
|
log_print(prio, "proc=[parent] log=[%s]\n", str);
|
||||||
else
|
else
|
||||||
syslog(prio, "[parent]: %s", str);
|
syslog(prio, "proc=[parent] log=[%s]", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
kore_buf_cleanup(&buf);
|
kore_buf_cleanup(&buf);
|
||||||
|
@ -120,10 +120,10 @@ log_from_worker(struct kore_msg *msg, const void *data)
|
||||||
name = kore_worker_name(wlog->wid);
|
name = kore_worker_name(wlog->wid);
|
||||||
|
|
||||||
if (kore_foreground || fp != stdout) {
|
if (kore_foreground || fp != stdout) {
|
||||||
log_print(wlog->prio, "%s: %.*s\n",
|
log_print(wlog->prio, "proc=%s log=[%.*s]\n",
|
||||||
name, (int)wlog->loglen, wlog->logmsg);
|
name, (int)wlog->loglen, wlog->logmsg);
|
||||||
} else {
|
} else {
|
||||||
syslog(wlog->prio, "%s: %.*s",
|
syslog(wlog->prio, "proc=%s log=[%.*s]",
|
||||||
name, (int)wlog->loglen, wlog->logmsg);
|
name, (int)wlog->loglen, wlog->logmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue