summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/en/weechat_dev.en.adoc1
-rw-r--r--doc/fr/weechat_dev.fr.adoc1
-rw-r--r--doc/ja/weechat_dev.ja.adoc1
-rw-r--r--po/POTFILES.in2
-rw-r--r--po/srcfiles.cmake2
-rw-r--r--src/plugins/logger/CMakeLists.txt1
-rw-r--r--src/plugins/logger/Makefile.am2
-rw-r--r--src/plugins/logger/logger-command.c206
-rw-r--r--src/plugins/logger/logger-command.h25
-rw-r--r--src/plugins/logger/logger.c171
-rw-r--r--src/plugins/logger/logger.h4
11 files changed, 247 insertions, 169 deletions
diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc
index 73dcca855..da3366d0e 100644
--- a/doc/en/weechat_dev.en.adoc
+++ b/doc/en/weechat_dev.en.adoc
@@ -290,6 +290,7 @@ WeeChat "core" is located in following directories:
|    logger/ | Logger plugin.
|       logger.c | Main logger functions.
|       logger-buffer.c | Logger buffer list management.
+|       logger-command.c | Logger commands.
|       logger-config.c | Logger config options (file logger.conf).
|       logger-info.c | Logger info/infolists/hdata.
|       logger-tail.c | Functions to get last lines of a file.
diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc
index 799aadd0c..71b88de1d 100644
--- a/doc/fr/weechat_dev.fr.adoc
+++ b/doc/fr/weechat_dev.fr.adoc
@@ -292,6 +292,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|    logger/ | Extension Logger.
|       logger.c | Fonctions principales pour Logger.
|       logger-buffer.c | Gestion des listes de tampons pour Logger.
+|       logger-command.c | Commandes de Logger.
|       logger-config.c | Options de configuration pour Logger (fichier logger.conf).
|       logger-info.c | Info/infolists/hdata pour Logger.
|       logger-tail.c | Fonctions pour obtenir les dernières lignes d'un fichier.
diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc
index cac24c2f1..aeee5acb9 100644
--- a/doc/ja/weechat_dev.ja.adoc
+++ b/doc/ja/weechat_dev.ja.adoc
@@ -296,6 +296,7 @@ WeeChat "core" は以下のディレクトリに配置されています:
|    logger/ | logger プラグイン
|       logger.c | logger の主要関数
|       logger-buffer.c | logger バッファリスト管理
+|       logger-command.c | logger コマンド
|       logger-config.c | logger 設定オプション (logger.conf ファイル)
|       logger-info.c | logger の情報/インフォリスト/hdata
|       logger-tail.c | ファイル末尾の行を返す
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8fac8cab6..2aff3b5e7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -266,6 +266,8 @@
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger.c
+./src/plugins/logger/logger-command.c
+./src/plugins/logger/logger-command.h
./src/plugins/logger/logger-config.c
./src/plugins/logger/logger-config.h
./src/plugins/logger/logger.h
diff --git a/po/srcfiles.cmake b/po/srcfiles.cmake
index fdabd7ade..23e057f11 100644
--- a/po/srcfiles.cmake
+++ b/po/srcfiles.cmake
@@ -267,6 +267,8 @@ SET(WEECHAT_SOURCES
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger.c
+./src/plugins/logger/logger-command.c
+./src/plugins/logger/logger-command.h
./src/plugins/logger/logger-config.c
./src/plugins/logger/logger-config.h
./src/plugins/logger/logger.h
diff --git a/src/plugins/logger/CMakeLists.txt b/src/plugins/logger/CMakeLists.txt
index c889a333f..e52325f3c 100644
--- a/src/plugins/logger/CMakeLists.txt
+++ b/src/plugins/logger/CMakeLists.txt
@@ -20,6 +20,7 @@
add_library(logger MODULE
logger.c logger.h
logger-buffer.c logger-buffer.h
+logger-command.c logger-command.h
logger-config.c logger-config.h
logger-info.c logger-info.h
logger-tail.c logger-tail.h)
diff --git a/src/plugins/logger/Makefile.am b/src/plugins/logger/Makefile.am
index d7dc276cf..773667569 100644
--- a/src/plugins/logger/Makefile.am
+++ b/src/plugins/logger/Makefile.am
@@ -27,6 +27,8 @@ logger_la_SOURCES = logger.c \
logger.h \
logger-buffer.c \
logger-buffer.h \
+ logger-command.c \
+ logger-command.h \
logger-config.c \
logger-config.h \
logger-info.c \
diff --git a/src/plugins/logger/logger-command.c b/src/plugins/logger/logger-command.c
new file mode 100644
index 000000000..eb54b27cb
--- /dev/null
+++ b/src/plugins/logger/logger-command.c
@@ -0,0 +1,206 @@
+/*
+ * logger-command.c - logger commands
+ *
+ * Copyright (C) 2003-2018 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "../weechat-plugin.h"
+#include "logger.h"
+#include "logger-buffer.h"
+#include "logger-config.h"
+
+
+/*
+ * Displays logging status for buffers.
+ */
+
+void
+logger_list ()
+{
+ struct t_infolist *ptr_infolist;
+ struct t_logger_buffer *ptr_logger_buffer;
+ struct t_gui_buffer *ptr_buffer;
+ char status[128];
+
+ weechat_printf (NULL, "");
+ weechat_printf (NULL, _("Logging on buffers:"));
+
+ ptr_infolist = weechat_infolist_get ("buffer", NULL, NULL);
+ if (ptr_infolist)
+ {
+ while (weechat_infolist_next (ptr_infolist))
+ {
+ ptr_buffer = weechat_infolist_pointer (ptr_infolist, "pointer");
+ if (ptr_buffer)
+ {
+ ptr_logger_buffer = logger_buffer_search_buffer (ptr_buffer);
+ if (ptr_logger_buffer)
+ {
+ snprintf (status, sizeof (status),
+ _("logging (level: %d)"),
+ ptr_logger_buffer->log_level);
+ }
+ else
+ {
+ snprintf (status, sizeof (status), "%s", _("not logging"));
+ }
+ weechat_printf (NULL,
+ " %s[%s%d%s]%s (%s) %s%s%s: %s%s%s%s",
+ weechat_color ("chat_delimiters"),
+ weechat_color ("chat"),
+ weechat_infolist_integer (ptr_infolist, "number"),
+ weechat_color ("chat_delimiters"),
+ weechat_color ("chat"),
+ weechat_infolist_string (ptr_infolist, "plugin_name"),
+ weechat_color ("chat_buffer"),
+ weechat_infolist_string (ptr_infolist, "name"),
+ weechat_color ("chat"),
+ status,
+ (ptr_logger_buffer) ? " (" : "",
+ (ptr_logger_buffer) ?
+ ((ptr_logger_buffer->log_filename) ?
+ ptr_logger_buffer->log_filename : _("log not started")) : "",
+ (ptr_logger_buffer) ? ")" : "");
+ }
+ }
+ weechat_infolist_free (ptr_infolist);
+ }
+}
+
+/*
+ * Enables/disables logging on a buffer.
+ */
+
+void
+logger_set_buffer (struct t_gui_buffer *buffer, const char *value)
+{
+ char *name;
+ struct t_config_option *ptr_option;
+
+ name = logger_build_option_name (buffer);
+ if (!name)
+ return;
+
+ if (logger_config_set_level (name, value) != WEECHAT_CONFIG_OPTION_SET_ERROR)
+ {
+ ptr_option = logger_config_get_level (name);
+ if (ptr_option)
+ {
+ weechat_printf (NULL, _("%s: \"%s\" => level %d"),
+ LOGGER_PLUGIN_NAME, name,
+ weechat_config_integer (ptr_option));
+ }
+ }
+
+ free (name);
+}
+
+/*
+ * Callback for command "/logger".
+ */
+
+int
+logger_command_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer,
+ int argc, char **argv, char **argv_eol)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) argv_eol;
+
+ if ((argc == 1)
+ || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0)))
+ {
+ logger_list ();
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "set") == 0)
+ {
+ if (argc > 2)
+ logger_set_buffer (buffer, argv[2]);
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "flush") == 0)
+ {
+ logger_flush ();
+ return WEECHAT_RC_OK;
+ }
+
+ if (weechat_strcasecmp (argv[1], "disable") == 0)
+ {
+ logger_set_buffer (buffer, "0");
+ return WEECHAT_RC_OK;
+ }
+
+ WEECHAT_COMMAND_ERROR;
+}
+
+/*
+ * Hooks logger commands.
+ */
+
+void
+logger_command_init ()
+{
+ weechat_hook_command (
+ "logger",
+ N_("logger plugin configuration"),
+ N_("list"
+ " || set <level>"
+ " || flush"
+ " || disable"),
+ N_(" list: show logging status for opened buffers\n"
+ " set: set logging level on current buffer\n"
+ " level: level for messages to be logged (0 = logging disabled, "
+ "1 = a few messages (most important) .. 9 = all messages)\n"
+ " flush: write all log files now\n"
+ "disable: disable logging on current buffer (set level to 0)\n"
+ "\n"
+ "Options \"logger.level.*\" and \"logger.mask.*\" can be used to set "
+ "level or mask for a buffer, or buffers beginning with name.\n"
+ "\n"
+ "Log levels used by IRC plugin:\n"
+ " 1: user message, notice, private\n"
+ " 2: nick change\n"
+ " 3: server message\n"
+ " 4: join/part/quit\n"
+ " 9: all other messages\n"
+ "\n"
+ "Examples:\n"
+ " set level to 5 for current buffer:\n"
+ " /logger set 5\n"
+ " disable logging for current buffer:\n"
+ " /logger disable\n"
+ " set level to 3 for all IRC buffers:\n"
+ " /set logger.level.irc 3\n"
+ " disable logging for main WeeChat buffer:\n"
+ " /set logger.level.core.weechat 0\n"
+ " use a directory per IRC server and a file per channel inside:\n"
+ " /set logger.mask.irc \"$server/$channel.weechatlog\""),
+ "list"
+ " || set 1|2|3|4|5|6|7|8|9"
+ " || flush"
+ " || disable",
+ &logger_command_cb, NULL, NULL);
+}
diff --git a/src/plugins/logger/logger-command.h b/src/plugins/logger/logger-command.h
new file mode 100644
index 000000000..6357ae4a2
--- /dev/null
+++ b/src/plugins/logger/logger-command.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2003-2018 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WEECHAT_PLUGIN_LOGGER_COMMAND_H
+#define WEECHAT_PLUGIN_LOGGER_COMMAND_H
+
+extern void logger_command_init ();
+
+#endif /* WEECHAT_PLUGIN_LOGGER_COMMAND_H */
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index a6014464a..1abb998ce 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -40,6 +40,7 @@
#include "../weechat-plugin.h"
#include "logger.h"
#include "logger-buffer.h"
+#include "logger-command.h"
#include "logger-config.h"
#include "logger-info.h"
#include "logger-tail.h"
@@ -740,91 +741,6 @@ logger_start_buffer_all (int write_info_line)
}
/*
- * Displays logging status for buffers.
- */
-
-void
-logger_list ()
-{
- struct t_infolist *ptr_infolist;
- struct t_logger_buffer *ptr_logger_buffer;
- struct t_gui_buffer *ptr_buffer;
- char status[128];
-
- weechat_printf (NULL, "");
- weechat_printf (NULL, _("Logging on buffers:"));
-
- ptr_infolist = weechat_infolist_get ("buffer", NULL, NULL);
- if (ptr_infolist)
- {
- while (weechat_infolist_next (ptr_infolist))
- {
- ptr_buffer = weechat_infolist_pointer (ptr_infolist, "pointer");
- if (ptr_buffer)
- {
- ptr_logger_buffer = logger_buffer_search_buffer (ptr_buffer);
- if (ptr_logger_buffer)
- {
- snprintf (status, sizeof (status),
- _("logging (level: %d)"),
- ptr_logger_buffer->log_level);
- }
- else
- {
- snprintf (status, sizeof (status), "%s", _("not logging"));
- }
- weechat_printf (NULL,
- " %s[%s%d%s]%s (%s) %s%s%s: %s%s%s%s",
- weechat_color ("chat_delimiters"),
- weechat_color ("chat"),
- weechat_infolist_integer (ptr_infolist, "number"),
- weechat_color ("chat_delimiters"),
- weechat_color ("chat"),
- weechat_infolist_string (ptr_infolist, "plugin_name"),
- weechat_color ("chat_buffer"),
- weechat_infolist_string (ptr_infolist, "name"),
- weechat_color ("chat"),
- status,
- (ptr_logger_buffer) ? " (" : "",
- (ptr_logger_buffer) ?
- ((ptr_logger_buffer->log_filename) ?
- ptr_logger_buffer->log_filename : _("log not started")) : "",
- (ptr_logger_buffer) ? ")" : "");
- }
- }
- weechat_infolist_free (ptr_infolist);
- }
-}
-
-/*
- * Enables/disables logging on a buffer.
- */
-
-void
-logger_set_buffer (struct t_gui_buffer *buffer, const char *value)
-{
- char *name;
- struct t_config_option *ptr_option;
-
- name = logger_build_option_name (buffer);
- if (!name)
- return;
-
- if (logger_config_set_level (name, value) != WEECHAT_CONFIG_OPTION_SET_ERROR)
- {
- ptr_option = logger_config_get_level (name);
- if (ptr_option)
- {
- weechat_printf (NULL, _("%s: \"%s\" => level %d"),
- LOGGER_PLUGIN_NAME, name,
- weechat_config_integer (ptr_option));
- }
- }
-
- free (name);
-}
-
-/*
* Flushes all log files.
*/
@@ -854,49 +770,6 @@ logger_flush ()
}
/*
- * Callback for command "/logger".
- */
-
-int
-logger_command_cb (const void *pointer, void *data,
- struct t_gui_buffer *buffer,
- int argc, char **argv, char **argv_eol)
-{
- /* make C compiler happy */
- (void) pointer;
- (void) data;
- (void) argv_eol;
-
- if ((argc == 1)
- || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0)))
- {
- logger_list ();
- return WEECHAT_RC_OK;
- }
-
- if (weechat_strcasecmp (argv[1], "set") == 0)
- {
- if (argc > 2)
- logger_set_buffer (buffer, argv[2]);
- return WEECHAT_RC_OK;
- }
-
- if (weechat_strcasecmp (argv[1], "flush") == 0)
- {
- logger_flush ();
- return WEECHAT_RC_OK;
- }
-
- if (weechat_strcasecmp (argv[1], "disable") == 0)
- {
- logger_set_buffer (buffer, "0");
- return WEECHAT_RC_OK;
- }
-
- WEECHAT_COMMAND_ERROR;
-}
-
-/*
* Callback for signal "buffer_opened".
*/
@@ -1385,47 +1258,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
logger_config_read ();
- /* command /logger */
- weechat_hook_command (
- "logger",
- N_("logger plugin configuration"),
- N_("list"
- " || set <level>"
- " || flush"
- " || disable"),
- N_(" list: show logging status for opened buffers\n"
- " set: set logging level on current buffer\n"
- " level: level for messages to be logged (0 = logging disabled, "
- "1 = a few messages (most important) .. 9 = all messages)\n"
- " flush: write all log files now\n"
- "disable: disable logging on current buffer (set level to 0)\n"
- "\n"
- "Options \"logger.level.*\" and \"logger.mask.*\" can be used to set "
- "level or mask for a buffer, or buffers beginning with name.\n"
- "\n"
- "Log levels used by IRC plugin:\n"
- " 1: user message, notice, private\n"
- " 2: nick change\n"
- " 3: server message\n"
- " 4: join/part/quit\n"
- " 9: all other messages\n"
- "\n"
- "Examples:\n"
- " set level to 5 for current buffer:\n"
- " /logger set 5\n"
- " disable logging for current buffer:\n"
- " /logger disable\n"
- " set level to 3 for all IRC buffers:\n"
- " /set logger.level.irc 3\n"
- " disable logging for main WeeChat buffer:\n"
- " /set logger.level.core.weechat 0\n"
- " use a directory per IRC server and a file per channel inside:\n"
- " /set logger.mask.irc \"$server/$channel.weechatlog\""),
- "list"
- " || set 1|2|3|4|5|6|7|8|9"
- " || flush"
- " || disable",
- &logger_command_cb, NULL, NULL);
+ logger_command_init ();
logger_start_buffer_all (1);
diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h
index e1992bda2..04371ab4d 100644
--- a/src/plugins/logger/logger.h
+++ b/src/plugins/logger/logger.h
@@ -25,11 +25,15 @@
#define LOGGER_LEVEL_DEFAULT 9
+struct t_gui_buffer;
+
extern struct t_weechat_plugin *weechat_logger_plugin;
extern struct t_hook *logger_timer;
+extern char *logger_build_option_name (struct t_gui_buffer *buffer);
extern void logger_start_buffer_all (int write_info_line);
+extern void logger_flush ();
extern void logger_stop_all (int write_info_line);
extern void logger_adjust_log_filenames ();
extern int logger_timer_cb (const void *pointer, void *data,