From 257e5cbd53052a898cd401ce716baefbe1db4a37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 4 Aug 2021 21:11:51 +0200 Subject: [PATCH] lib/log kr_log_fmt(): pass parameters more properly Systemd docs say: > Those arguments must contain valid journal entries including > the variable name, e.g. "CODE_FILE=src/foo.c", [...] I tried that passing all three strings empty (without variable name) wouldn't result into the line getting logged; the suggested style does. --- daemon/lua/sandbox.lua.in | 3 ++- lib/log.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in index 4a513b258..8eebbfab7 100644 --- a/daemon/lua/sandbox.lua.in +++ b/daemon/lua/sandbox.lua.in @@ -31,7 +31,8 @@ local function curr_file() return debug.getinfo(4,'S').source end local function curr_line() return debug.getinfo(4,'l').currentline end local function log_fmt(grp, level, fmt, ...) - ffi.C.kr_log_fmt(grp, level, 'CODE_FILE='..curr_file(), 'CODE_LINE='..curr_line(), '', + ffi.C.kr_log_fmt(grp, level, + 'CODE_FILE='..curr_file(), 'CODE_LINE='..curr_line(), 'CODE_FUNC=', '[%-6s] %s\n', ffi.C.kr_log_grp2name(grp), string.format(fmt, ...)) end diff --git a/lib/log.h b/lib/log.h index 402963204..f5be3da3b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -261,6 +261,11 @@ bool kr_log_is_debug_fun(enum kr_log_group group, const struct kr_request *req); /* Helpers "internal" to log.* */ +/** @internal + * + * If you don't have location, pass ("CODE_FILE=", "CODE_LINE=", "CODE_FUNC=") + * Others than systemd don't utilize these metadata. + */ KR_EXPORT KR_PRINTF(6) void kr_log_fmt(enum kr_log_group group, kr_log_level_t level, const char *file, const char *line, const char *func, const char *fmt, ...); -- 2.47.2