summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
6 files changed, 240 insertions, 169 deletions
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,