From 809e674275fb681b1c5dcd936268c3fa35eee7b8 Mon Sep 17 00:00:00 2001 From: Kaitmazian Maksim <m.kaitmazian@picodata.io> Date: Tue, 8 Oct 2024 12:39:31 +0300 Subject: [PATCH] feat: add _say_filter hook NO_DOC=internal NO_TEST=internal NO_CHANGELOG=internal --- extra/exports | 3 +++ src/lib/core/say.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/extra/exports b/extra/exports index d679db1bfd..85437e5c42 100644 --- a/extra/exports +++ b/extra/exports @@ -675,3 +675,6 @@ log_destroy log_new log_say log_set_format_by_name + +# picodata log filter hook +_say_filter diff --git a/src/lib/core/say.c b/src/lib/core/say.c index b332286cba..486b84afa2 100644 --- a/src/lib/core/say.c +++ b/src/lib/core/say.c @@ -1372,6 +1372,19 @@ format_log_entry(struct log *log, int level, const char *module, return total; } +/** + * Hook defined in picodata that allows to filter logs from files that match + * a specified pattern. For instance, "pgproto=info" keeps log entries with + * a corresponding log level and that come from files with "pgproto" in their + * path. + * NULL is a valid value, meaning that there are no special rules to be + * applied, so all the filtering is handled by tarantool. + * + * Returns true for entries that should be kept, false otherwise. + */ +bool +(*_say_filter)(int level, const char *file) = NULL; + int log_vsay(struct log *log, int level, bool check_level, const char *module, const char *filename, int line, const char *error, const char *format, @@ -1382,6 +1395,10 @@ log_vsay(struct log *log, int level, bool check_level, const char *module, if (check_level && level > log->level) goto out; + /* Apply filtering rules, if any. */ + if (_say_filter && !_say_filter(level, filename)) + goto out; + total = format_log_entry(log, level, module, filename, line, error, format, ap); if (total <= 0) -- GitLab