From c3c218035a9325d47949bf56d57543b2a243098c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 20 May 2023 17:07:55 +0200 Subject: [PATCH] logger: add option logger.file.log_conditions (closes #1942) --- ChangeLog.adoc | 1 + doc/en/weechat_dev.en.adoc | 1 + doc/fr/weechat_dev.fr.adoc | 1 + doc/ja/weechat_dev.ja.adoc | 2 + doc/sr/weechat_dev.sr.adoc | 2 + po/cs.po | 8 +- po/de.po | 17 +- po/es.po | 8 +- po/fr.po | 14 +- po/hu.po | 8 +- po/it.po | 8 +- po/ja.po | 17 +- po/pl.po | 17 +- po/pt.po | 8 +- po/pt_BR.po | 8 +- po/ru.po | 8 +- po/sr.po | 17 +- po/tr.po | 17 +- po/weechat.pot | 8 +- src/plugins/logger/logger-backlog.c | 62 +---- src/plugins/logger/logger-backlog.h | 1 - src/plugins/logger/logger-buffer.c | 5 +- src/plugins/logger/logger-config.c | 11 + src/plugins/logger/logger-config.h | 1 + src/plugins/logger/logger.c | 56 +++++ src/plugins/logger/logger.h | 2 + tests/CMakeLists.txt | 1 + .../plugins/logger/test-logger-backlog.cpp | 10 - tests/unit/plugins/logger/test-logger.cpp | 214 ++++++++++++++++++ 29 files changed, 449 insertions(+), 84 deletions(-) create mode 100644 tests/unit/plugins/logger/test-logger.cpp diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 56f5e3137..d24485ffe 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -52,6 +52,7 @@ New features:: * irc: use key when /joining in open channel buffer (issue #1260) * irc: add option `buffer` in command `/autojoin sort` (issue #1876) * irc: add `${username}` in server options "nicks" and "username", change their default values to use it + * logger: add option logger.file.log_conditions (issue #1942) * logger: add info "logger_log_file" * relay: rename "ssl" options and protocol to "tls" * relay: make TLS certificate/key loading error handling more verbose (issue #1558) diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 5298cd428..108247a90 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -445,6 +445,7 @@ WeeChat "core" is located in following directories: |             test-irc-server.cpp | Tests: IRC server. |             test-irc-tag.cpp | Tests: IRC message tags. |          logger/ | Root of unit tests for logger plugin. +|             test-logger.cpp | Tests: logger. |             test-logger-backlog.cpp | Tests: logger backlog. |          trigger/ | Root of unit tests for trigger plugin. |             test-trigger.cpp | Tests: triggers. diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index 032f60007..3de692e54 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -447,6 +447,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : |             test-irc-server.cpp | Tests : serveur IRC. |             test-irc-tag.cpp | Tests : étiquettes des messages IRC. |          logger/ | Racine des tests unitaires pour l'extension logger. +|             test-logger.cpp | Tests : logger. |             test-logger-backlog.cpp | Tests : backlog logger. |          trigger/ | Racine des tests unitaires pour l'extension trigger. |             test-trigger.cpp | Tests : triggers. diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 12f3b718f..95d48ef7e 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -496,6 +496,8 @@ WeeChat "core" は以下のディレクトリに配置されています: // TRANSLATION MISSING |          logger/ | Root of unit tests for logger plugin. // TRANSLATION MISSING +|             test-logger.cpp | Tests: logger. +// TRANSLATION MISSING |             test-logger-backlog.cpp | Tests: logger backlog. // TRANSLATION MISSING |          trigger/ | Root of unit tests for trigger plugin. diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index f670041c1..c237df97a 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -449,6 +449,8 @@ WeeChat „језгро” се налази у следећим директо |             test-irc-server.cpp | Тестови: IRC сервер. |             test-irc-tag.cpp | Тестови: IRC ознаке порука. |          logger/ | Корен unit тестива за logger додатак. +// TRANSLATION MISSING +|             test-logger.cpp | Tests: logger. |             test-logger-backlog.cpp | Тестови: logger заостатак. |          trigger/ | Корен unit тестова за окидач додатак. |             test-trigger.cpp | Тестови: окидачи. diff --git a/po/cs.po b/po/cs.po index 3c0b25061..fd291843f 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -10802,6 +10802,12 @@ msgstr "" "zapsat informační řádek do logovacího souboru při spuštění nebo skončení pro " "buffer" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + #, fuzzy msgid "" "default file name mask for log files (format is \"directory/to/file\" or " diff --git a/po/de.po b/po/de.po index af6e35979..2942d9a09 100644 --- a/po/de.po +++ b/po/de.po @@ -26,7 +26,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-14 15:49+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -13170,6 +13170,21 @@ msgstr "" "fügt eine Information in die Protokoll-Datei ein, wenn die Protokollierung " "gestartet oder beendet wird" +#, fuzzy +#| msgid "" +#| "conditions to display the backlog (note: content is evaluated, see /help " +#| "eval); empty value displays the backlog on all buffers; for example to " +#| "display backlog on private buffers only: \"${type} == private\"" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" +"Bedingungen um die Protokolldatei anzuzeigen (Hinweis: Der Inhalt ist " +"evaluiert, siehe /help eval); wird kein Wert angegeben, wird die " +"Protokolldatei bei allen Buffern angezeigt ; Beispiel: um nur bei privaten " +"Buffern die Protokolldatei anzuzeigen: \"${type} == private\"" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/es.po b/po/es.po index 817f9af93..7a03618fe 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Santiago Forero \n" "Language-Team: weechat-dev \n" @@ -11537,6 +11537,12 @@ msgstr "" "escribir una línea informativa en el registro cuando el registro empieza o " "termina en un buffer" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + #, fuzzy msgid "" "default file name mask for log files (format is \"directory/to/file\" or " diff --git a/po/fr.po b/po/fr.po index 2c4d216ac..e0e1ff34e 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" -"PO-Revision-Date: 2023-05-18 11:51+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" +"PO-Revision-Date: 2023-05-20 16:59+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -12866,6 +12866,16 @@ msgstr "" "écrire une ligne d'information dans le fichier log quand le log démarre ou " "se termine pour un tampon" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" +"conditions pour sauver le contenu des tampons dans des fichiers (note : le " +"contenu est évalué, voir /help eval) ; une valeur vide sauve le contenu de " +"tous les tampons ; par exemple pour sauver uniquement les tampons privés : " +"\"${type} == private\"" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/hu.po b/po/hu.po index 78873ecf1..33e9dff6b 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -10183,6 +10183,12 @@ msgstr "" msgid "write information line in log file when log starts or ends for a buffer" msgstr "" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/it.po b/po/it.po index 991f0d260..0a08a6b90 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -11259,6 +11259,12 @@ msgstr "" "scrive una riga informativa nel file di log quando il log inizia o termina " "per un buffer" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + #, fuzzy msgid "" "default file name mask for log files (format is \"directory/to/file\" or " diff --git a/po/ja.po b/po/ja.po index 3cde5832c..0f1389a5f 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" "Language-Team: Polish \n" @@ -13448,6 +13448,21 @@ msgstr "" "zapisuje informacje w pliku z logami o rozpoczęciu i zakończeniu logowania " "buforu" +#, fuzzy +#| msgid "" +#| "conditions to display the backlog (note: content is evaluated, see /help " +#| "eval); empty value displays the backlog on all buffers; for example to " +#| "display backlog on private buffers only: \"${type} == private\"" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" +"warunki do wyświetlania backlogu (uwaga: zawartość jest przetwarzana, " +"zobacz /help eval); pusta wartość wyświetla backlog we wszystkich buforach; " +"na przykład żeby wyświetlić backlog tylko w prywatnych buforach: \"${type} " +"== private\"" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/pt.po b/po/pt.po index 0ebf24c84..3d7e29ccb 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -12232,6 +12232,12 @@ msgstr "" "escrever linha de informação no ficheiro de registo quando o registo de um " "buffer inicia ou termina" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/pt_BR.po b/po/pt_BR.po index 4ea7e03b5..ba5ae611d 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Érico Nogueira \n" "Language-Team: weechat-dev \n" @@ -10755,6 +10755,12 @@ msgstr "" "escrever linha de informação no arquivo de registro quando o registro " "começar ou terminar para um buffer" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + #, fuzzy msgid "" "default file name mask for log files (format is \"directory/to/file\" or " diff --git a/po/ru.po b/po/ru.po index 620cf6ff4..7868e2dc4 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -10221,6 +10221,12 @@ msgstr "" msgid "write information line in log file when log starts or ends for a buffer" msgstr "" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/sr.po b/po/sr.po index 65b3bb1c7..cc831c124 100644 --- a/po/sr.po +++ b/po/sr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-14 15:29+0200\n" "Last-Translator: Ivan Pešić \n" "Language-Team: weechat-dev \n" @@ -12622,6 +12622,21 @@ msgstr "" "упис линије са информацијама у лог фајл када се започне или заустави " "логовање за бафер" +#, fuzzy +#| msgid "" +#| "conditions to display the backlog (note: content is evaluated, see /help " +#| "eval); empty value displays the backlog on all buffers; for example to " +#| "display backlog on private buffers only: \"${type} == private\"" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" +"услови под којима се приказују старије линије (напомена: садржај се " +"израчунава, погледајте /help eval); празна вредност приказује старије линије " +"на свим баферима; на пример, ако желите да се старије линије приказују само " +"за приватне бафере: „${type} == private”" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/tr.po b/po/tr.po index b8d9877be..49350a70d 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Emir SARI \n" "Language-Team: weechat-dev \n" @@ -13008,6 +13008,21 @@ msgstr "" "bir arabellek için günlük başladığında veya bittiğinde bilgi satırını günlük " "dosyasına yaz" +#, fuzzy +#| msgid "" +#| "conditions to display the backlog (note: content is evaluated, see /help " +#| "eval); empty value displays the backlog on all buffers; for example to " +#| "display backlog on private buffers only: \"${type} == private\"" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" +"biriken günlüğü görüntüleme koşulları (not: içerik değerlendirilir, bkz. /" +"help eval); boş değer, biriken günlüğü tüm arabelleklerde görüntüler; " +"örneğin biriken günlüğü yalnızca gizli arabelleklerde görüntülemek için: " +"\"${type} == private\"" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/po/weechat.pot b/po/weechat.pot index 50ebdae25..e6f1fc07c 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-18 11:42+0200\n" +"POT-Creation-Date: 2023-05-20 16:55+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -9209,6 +9209,12 @@ msgstr "" msgid "write information line in log file when log starts or ends for a buffer" msgstr "" +msgid "" +"conditions to save content of buffers to files (note: content is evaluated, " +"see /help eval); empty value saves content on all buffers; for example to " +"log only private buffers: \"${type} == private\"" +msgstr "" + msgid "" "default file name mask for log files (format is \"directory/to/file\" or " "\"file\", without first \"/\" because \"path\" option is used to build " diff --git a/src/plugins/logger/logger-backlog.c b/src/plugins/logger/logger-backlog.c index 14ed7bffb..c85999a36 100644 --- a/src/plugins/logger/logger-backlog.c +++ b/src/plugins/logger/logger-backlog.c @@ -46,62 +46,6 @@ #include "logger-tail.h" -/* - * Checks conditions to display the backlog. - * - * Returns: - * 1: conditions OK (backlog is displayed) - * 0: conditions not OK (backlog is NOT displayed) - */ - -int -logger_backlog_check_conditions (struct t_gui_buffer *buffer) -{ - struct t_hashtable *pointers, *options; - const char *ptr_condition; - char *result; - int condition_ok; - - ptr_condition = weechat_config_string (logger_config_look_backlog_conditions); - - /* empty condition displays the backlog everywhere */ - if (!ptr_condition || !ptr_condition[0]) - return 1; - - pointers = weechat_hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_POINTER, - NULL, - NULL); - if (pointers) - { - weechat_hashtable_set (pointers, "window", - weechat_window_search_with_buffer (buffer)); - weechat_hashtable_set (pointers, "buffer", buffer); - } - - options = weechat_hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (options) - weechat_hashtable_set (options, "type", "condition"); - - result = weechat_string_eval_expression (ptr_condition, - pointers, NULL, options); - condition_ok = (result && (strcmp (result, "1") == 0)); - if (result) - free (result); - - if (pointers) - weechat_hashtable_free (pointers); - if (options) - weechat_hashtable_free (options); - - return condition_ok; -} - /* * Displays a line read from log file. */ @@ -227,6 +171,7 @@ logger_backlog_signal_cb (const void *pointer, void *data, const char *type_data, void *signal_data) { struct t_logger_buffer *ptr_logger_buffer; + int rc; /* make C compiler happy */ (void) pointer; @@ -237,7 +182,10 @@ logger_backlog_signal_cb (const void *pointer, void *data, if (weechat_config_integer (logger_config_look_backlog) == 0) return WEECHAT_RC_OK; - if (!logger_backlog_check_conditions (signal_data)) + rc = logger_check_conditions ( + signal_data, + weechat_config_string (logger_config_look_backlog_conditions)); + if (!rc) return WEECHAT_RC_OK; ptr_logger_buffer = logger_buffer_search_buffer (signal_data); diff --git a/src/plugins/logger/logger-backlog.h b/src/plugins/logger/logger-backlog.h index 39b13933b..779fd2df7 100644 --- a/src/plugins/logger/logger-backlog.h +++ b/src/plugins/logger/logger-backlog.h @@ -20,7 +20,6 @@ #ifndef WEECHAT_PLUGIN_LOGGER_BACKLOG_H #define WEECHAT_PLUGIN_LOGGER_BACKLOG_H -extern int logger_backlog_check_conditions (struct t_gui_buffer *buffer); extern int logger_backlog_signal_cb (const void *pointer, void *data, const char *signal, const char *type_data, void *signal_data); diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c index 9c02ded58..67686abb7 100644 --- a/src/plugins/logger/logger-buffer.c +++ b/src/plugins/logger/logger-buffer.c @@ -713,7 +713,10 @@ logger_buffer_start (struct t_gui_buffer *buffer, int write_info_line) log_level = logger_get_level_for_buffer (buffer); log_enabled = weechat_config_boolean (logger_config_file_auto_log) - && (log_level > 0); + && (log_level > 0) + && (logger_check_conditions ( + buffer, + weechat_config_string (logger_config_file_log_conditions))); ptr_logger_buffer = logger_buffer_search_buffer (buffer); diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c index 91683f2b8..1b5dd5c97 100644 --- a/src/plugins/logger/logger-config.c +++ b/src/plugins/logger/logger-config.c @@ -58,6 +58,7 @@ struct t_config_option *logger_config_file_color_lines = NULL; struct t_config_option *logger_config_file_flush_delay = NULL; struct t_config_option *logger_config_file_fsync = NULL; struct t_config_option *logger_config_file_info_lines = NULL; +struct t_config_option *logger_config_file_log_conditions = NULL; struct t_config_option *logger_config_file_mask = NULL; struct t_config_option *logger_config_file_name_lower_case = NULL; struct t_config_option *logger_config_file_nick_prefix = NULL; @@ -579,6 +580,16 @@ logger_config_init () "a buffer"), NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + logger_config_file_log_conditions = weechat_config_new_option ( + logger_config_file, logger_config_section_file, + "log_conditions", "string", + N_("conditions to save content of buffers to files " + "(note: content is evaluated, see /help eval); " + "empty value saves content on all buffers; " + "for example to log only private buffers: " + "\"${type} == private\""), + NULL, 0, 0, "", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); logger_config_file_mask = weechat_config_new_option ( logger_config_file, logger_config_section_file, "mask", "string", diff --git a/src/plugins/logger/logger-config.h b/src/plugins/logger/logger-config.h index 45ec8aad5..ca0631a0e 100644 --- a/src/plugins/logger/logger-config.h +++ b/src/plugins/logger/logger-config.h @@ -34,6 +34,7 @@ extern struct t_config_option *logger_config_file_color_lines; extern struct t_config_option *logger_config_file_flush_delay; extern struct t_config_option *logger_config_file_fsync; extern struct t_config_option *logger_config_file_info_lines; +extern struct t_config_option *logger_config_file_log_conditions; extern struct t_config_option *logger_config_file_mask; extern struct t_config_option *logger_config_file_name_lower_case; extern struct t_config_option *logger_config_file_nick_prefix; diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index ef817faa3..6489ef1ec 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -49,6 +49,62 @@ struct t_hook *logger_hook_timer = NULL; /* timer to flush log files */ struct t_hook *logger_hook_print = NULL; +/* + * Checks conditions against a buffer. + * + * Returns: + * 1: conditions OK + * 0: conditions not OK + */ + +int +logger_check_conditions (struct t_gui_buffer *buffer, const char *conditions) +{ + struct t_hashtable *pointers, *options; + char *result; + int condition_ok; + + if (!buffer) + return 0; + + /* empty conditions = always true */ + if (!conditions || !conditions[0]) + return 1; + + pointers = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); + if (pointers) + { + weechat_hashtable_set (pointers, "window", + weechat_window_search_with_buffer (buffer)); + weechat_hashtable_set (pointers, "buffer", buffer); + } + + options = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); + if (options) + weechat_hashtable_set (options, "type", "condition"); + + result = weechat_string_eval_expression (conditions, + pointers, NULL, options); + condition_ok = (result && (strcmp (result, "1") == 0)); + if (result) + free (result); + + if (pointers) + weechat_hashtable_free (pointers); + if (options) + weechat_hashtable_free (options); + + return condition_ok; +} + /* * Gets logger file path option. * diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h index e1b5a137e..2b94acab4 100644 --- a/src/plugins/logger/logger.h +++ b/src/plugins/logger/logger.h @@ -34,6 +34,8 @@ extern struct t_weechat_plugin *weechat_logger_plugin; extern struct t_hook *logger_hook_timer; extern struct t_hook *logger_hook_print; +extern int logger_check_conditions (struct t_gui_buffer *buffer, + const char *conditions); extern int logger_create_directory (); extern char *logger_build_option_name (struct t_gui_buffer *buffer); extern int logger_get_level_for_buffer (struct t_gui_buffer *buffer); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d0fe4af2a..51c65e1cb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -89,6 +89,7 @@ endif() if(ENABLE_LOGGER) list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC + unit/plugins/logger/test-logger.cpp unit/plugins/logger/test-logger-backlog.cpp ) endif() diff --git a/tests/unit/plugins/logger/test-logger-backlog.cpp b/tests/unit/plugins/logger/test-logger-backlog.cpp index 4030b2a36..b399e3d46 100644 --- a/tests/unit/plugins/logger/test-logger-backlog.cpp +++ b/tests/unit/plugins/logger/test-logger-backlog.cpp @@ -40,16 +40,6 @@ TEST_GROUP(LoggerBacklog) { }; -/* - * Tests functions: - * logger_backlog_check_conditions - */ - -TEST(LoggerBacklog, CheckConditions) -{ - /* TODO: write tests */ -} - /* * Tests functions: * logger_backlog_display_line diff --git a/tests/unit/plugins/logger/test-logger.cpp b/tests/unit/plugins/logger/test-logger.cpp new file mode 100644 index 000000000..a4005efe1 --- /dev/null +++ b/tests/unit/plugins/logger/test-logger.cpp @@ -0,0 +1,214 @@ +/* + * test-logger.cpp - test logger functions + * + * Copyright (C) 2023 Sébastien Helleu + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see . + */ + +#include "CppUTest/TestHarness.h" + +#include "tests/tests.h" + +extern "C" +{ +#include "src/gui/gui-buffer.h" +#include "src/plugins/logger/logger.h" +} + +TEST_GROUP(Logger) +{ +}; + +/* + * Tests functions: + * logger_check_conditions + */ + +TEST(Logger, CheckConditions) +{ + LONGS_EQUAL(0, logger_check_conditions (NULL, NULL)); + LONGS_EQUAL(0, logger_check_conditions (NULL, "")); + LONGS_EQUAL(0, logger_check_conditions (NULL, "1")); + + LONGS_EQUAL(1, logger_check_conditions (gui_buffers, NULL)); + LONGS_EQUAL(1, logger_check_conditions (gui_buffers, "")); + LONGS_EQUAL(1, logger_check_conditions (gui_buffers, "1")); + LONGS_EQUAL(1, logger_check_conditions (gui_buffers, "${name} == weechat")); + + LONGS_EQUAL(0, logger_check_conditions (gui_buffers, "0")); + LONGS_EQUAL(0, logger_check_conditions (gui_buffers, "${name} == test")); +} + +/* + * Tests functions: + * logger_get_file_path + */ + +TEST(Logger, GetFilePath) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_create_directory + */ + +TEST(Logger, CreateDirectory) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_build_option_name + */ + +TEST(Logger, BuildOptionName) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_get_level_for_buffer + */ + +TEST(Logger, GetLevelForBuffer) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_get_mask_for_buffer + */ + +TEST(Logger, GetMaskForBuffer) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_get_mask_expanded + */ + +TEST(Logger, GetMaskExpanded) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_get_filename + */ + +TEST(Logger, GetFilename) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_buffer_opened_signal_cb + */ + +TEST(Logger, BufferOpenedSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_buffer_closing_signal_cb + */ + +TEST(Logger, BufferClosingSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_buffer_renamed_signal_cb + */ + +TEST(Logger, BufferRenamedSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_start_signal_cb + */ + +TEST(Logger, StartSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_stop_signal_cb + */ + +TEST(Logger, StopSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_day_changed_signal_cb + */ + +TEST(Logger, DayChangedSignalCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_get_line_tag_info + */ + +TEST(Logger, GetLineTagInfo) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_print_cb + */ + +TEST(Logger, PrintCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_timer_cb + */ + +TEST(Logger, TimerCb) +{ + /* TODO: write tests */ +}