diff --git a/extra/exports b/extra/exports index d679db1bfdc8aef0d11970ef7a6f57c24b3e3e8c..85437e5c42ceac7b77b7246e45ce5688731d0b79 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 b332286cbabf920f64afb3e29c8af04e7e02ee2a..486b84afa2125aefd73d9219072bdb40375af246 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)