kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit b77d727f729b4c2fd0b7cc1638cbed02c1d326c9
parent ff6bae6513eb5f1c86ef6ccf938bdc03807b9905
Author: Joris Vink <joris@coders.se>
Date:   Fri, 10 Sep 2021 13:34:57 +0200

Add a logfile configuration option.

This will log all output from Kore processes to the specified file.

Diffstat:
include/kore/kore.h | 1+
src/config.c | 9+++++++++
src/log.c | 17+++++++++++++++--
3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -855,6 +855,7 @@ int kore_connection_accept(struct listener *, u_int64_t kore_time_ms(void); void kore_log_init(void); +void kore_log_file(const char *); #if defined(KORE_USE_PYTHON) int kore_configure_setting(const char *, char *); diff --git a/src/config.c b/src/config.c @@ -81,6 +81,7 @@ static int configure_bind_unix(char *); static int configure_attach(char *); static int configure_domain(char *); static int configure_privsep(char *); +static int configure_logfile(char *); static int configure_workers(char *); static int configure_pidfile(char *); static int configure_rlimit_nofiles(char *); @@ -212,6 +213,7 @@ static struct { const char *name; int (*configure)(char *); } config_settings[] = { + { "logfile", configure_logfile }, { "workers", configure_workers }, { "worker_max_connections", configure_max_connections }, { "worker_rlimit_nofiles", configure_rlimit_nofiles }, @@ -1772,6 +1774,13 @@ configure_websocket_timeout(char *option) #endif /* !KORE_NO_HTTP */ static int +configure_logfile(char *path) +{ + kore_log_file(path); + return (KORE_RESULT_OK); +} + +static int configure_workers(char *option) { int err; diff --git a/src/log.c b/src/log.c @@ -30,6 +30,8 @@ struct kore_wlog { static void log_print(int, const char *, ...); static void log_from_worker(struct kore_msg *, const void *); +static FILE *fp = NULL; + void kore_log_init(void) { @@ -40,6 +42,8 @@ kore_log_init(void) const char *name = "kore"; #endif + fp = stdout; + if (!kore_foreground) openlog(name, LOG_NDELAY | LOG_PID, LOG_DAEMON); @@ -47,6 +51,15 @@ kore_log_init(void) } void +kore_log_file(const char *path) +{ + if ((fp = fopen(path, "a")) == NULL) { + fp = stdout; + fatal("fopen(%s): %s", path, errno_s); + } +} + +void kore_log(int prio, const char *fmt, ...) { va_list args; @@ -129,8 +142,8 @@ log_print(int prio, const char *fmt, ...) break; } - vprintf(fmt, args); - fflush(stdout); + vfprintf(fp, fmt, args); + fflush(fp); va_end(args); }