summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/logger/logger-backlog.c51
-rw-r--r--src/plugins/logger/logger-config.c51
-rw-r--r--src/plugins/logger/logger-config.h3
-rw-r--r--src/plugins/logger/logger.c94
-rw-r--r--src/plugins/logger/logger.h8
5 files changed, 148 insertions, 59 deletions
diff --git a/src/plugins/logger/logger-backlog.c b/src/plugins/logger/logger-backlog.c
index bfd3c022c..f1ff70aa1 100644
--- a/src/plugins/logger/logger-backlog.c
+++ b/src/plugins/logger/logger-backlog.c
@@ -110,13 +110,15 @@ void
logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines)
{
struct t_logger_line *last_lines, *ptr_lines;
- char *charset, *pos_message, *pos_tab, *error, *message;
+ char *charset, *pos_message, *pos_tab, *error, *message, *message2;
time_t datetime, time_now;
struct tm tm_line;
- int num_lines;
+ int color_lines, num_lines;
weechat_buffer_set (buffer, "print_hooks_enabled", "0");
+ color_lines = weechat_config_boolean (logger_config_file_color_lines);
+
num_lines = 0;
last_lines = logger_tail_file (filename, lines);
ptr_lines = last_lines;
@@ -145,26 +147,35 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines)
}
pos_message = (pos_message && (datetime != 0)) ?
pos_message + 1 : ptr_lines->data;
- charset = weechat_info_get ("charset_terminal", "");
- message = (charset) ?
- weechat_iconv_to_internal (charset, pos_message) : strdup (pos_message);
- if (charset)
- free (charset);
+ message = weechat_hook_modifier_exec (
+ "color_decode_ansi",
+ (color_lines) ? "1" : "0",
+ pos_message);
if (message)
{
- pos_tab = strchr (message, '\t');
- if (pos_tab)
- pos_tab[0] = '\0';
- weechat_printf_date_tags (buffer, datetime,
- "no_highlight,notify_none,logger_backlog",
- "%s%s%s%s%s",
- weechat_color (weechat_config_string (logger_config_color_backlog_line)),
- message,
- (pos_tab) ? "\t" : "",
- (pos_tab) ? weechat_color (weechat_config_string (logger_config_color_backlog_line)) : "",
- (pos_tab) ? pos_tab + 1 : "");
- if (pos_tab)
- pos_tab[0] = '\t';
+ charset = weechat_info_get ("charset_terminal", "");
+ message2 = (charset) ?
+ weechat_iconv_to_internal (charset, message) : strdup (message);
+ if (charset)
+ free (charset);
+ if (message2)
+ {
+ pos_tab = strchr (message2, '\t');
+ if (pos_tab)
+ pos_tab[0] = '\0';
+ weechat_printf_date_tags (
+ buffer, datetime,
+ "no_highlight,notify_none,logger_backlog",
+ "%s%s%s%s%s",
+ (color_lines) ? "" : weechat_color (weechat_config_string (logger_config_color_backlog_line)),
+ message2,
+ (pos_tab) ? "\t" : "",
+ (pos_tab && !color_lines) ? weechat_color (weechat_config_string (logger_config_color_backlog_line)) : "",
+ (pos_tab) ? pos_tab + 1 : "");
+ if (pos_tab)
+ pos_tab[0] = '\t';
+ free (message2);
+ }
free (message);
}
num_lines++;
diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c
index c2fae6909..e0dbaecbf 100644
--- a/src/plugins/logger/logger-config.c
+++ b/src/plugins/logger/logger-config.c
@@ -46,6 +46,7 @@ struct t_config_option *logger_config_color_backlog_line;
/* logger config, file section */
struct t_config_option *logger_config_file_auto_log;
+struct t_config_option *logger_config_file_color_lines;
struct t_config_option *logger_config_file_flush_delay;
struct t_config_option *logger_config_file_fsync;
struct t_config_option *logger_config_file_info_lines;
@@ -77,6 +78,31 @@ logger_config_change_file_option_restart_log (const void *pointer, void *data,
}
/*
+ * Callback for changes on option "logger.file.color_lines".
+ */
+
+void
+logger_config_color_lines_change (const void *pointer, void *data,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ if (logger_config_loading)
+ return;
+
+ if (logger_hook_print)
+ weechat_unhook (logger_hook_print);
+
+ logger_hook_print = weechat_hook_print (
+ NULL, NULL, NULL,
+ (weechat_config_boolean (logger_config_file_color_lines)) ? 0 : 1,
+ &logger_print_cb, NULL, NULL);
+}
+
+/*
* Callback for changes on option "logger.file.flush_delay".
*/
@@ -92,7 +118,7 @@ logger_config_flush_delay_change (const void *pointer, void *data,
if (logger_config_loading)
return;
- if (logger_timer)
+ if (logger_hook_timer)
{
if (weechat_logger_plugin->debug)
{
@@ -100,8 +126,8 @@ logger_config_flush_delay_change (const void *pointer, void *data,
NULL, 0, "no_log",
"%s: stopping timer", LOGGER_PLUGIN_NAME);
}
- weechat_unhook (logger_timer);
- logger_timer = NULL;
+ weechat_unhook (logger_hook_timer);
+ logger_hook_timer = NULL;
}
if (weechat_config_integer (logger_config_file_flush_delay) > 0)
@@ -114,9 +140,10 @@ logger_config_flush_delay_change (const void *pointer, void *data,
LOGGER_PLUGIN_NAME,
weechat_config_integer (logger_config_file_flush_delay));
}
- logger_timer = weechat_hook_timer (weechat_config_integer (logger_config_file_flush_delay) * 1000,
- 0, 0,
- &logger_timer_cb, NULL, NULL);
+ logger_hook_timer = weechat_hook_timer (
+ weechat_config_integer (logger_config_file_flush_delay) * 1000,
+ 0, 0,
+ &logger_timer_cb, NULL, NULL);
}
}
@@ -435,7 +462,8 @@ logger_config_init ()
logger_config_color_backlog_line = weechat_config_new_option (
logger_config_file, ptr_section,
"backlog_line", "color",
- N_("color for backlog lines"),
+ N_("color for backlog lines, used only if the option "
+ "logger.file.color_lines is off"),
NULL, -1, 0, "default", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
@@ -461,6 +489,15 @@ logger_config_init ()
"disables log)"),
NULL, 0, 0, "on", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ logger_config_file_color_lines = weechat_config_new_option (
+ logger_config_file, ptr_section,
+ "color_lines", "boolean",
+ N_("use ANSI color codes in lines written in log files and display "
+ "backlog lines with these colors"),
+ NULL, 0, 0, "off", NULL, 0,
+ NULL, NULL, NULL,
+ &logger_config_color_lines_change, NULL, NULL,
+ NULL, NULL, NULL);
logger_config_file_flush_delay = weechat_config_new_option (
logger_config_file, ptr_section,
"flush_delay", "integer",
diff --git a/src/plugins/logger/logger-config.h b/src/plugins/logger/logger-config.h
index 207249a02..c3fce31f5 100644
--- a/src/plugins/logger/logger-config.h
+++ b/src/plugins/logger/logger-config.h
@@ -30,6 +30,7 @@ extern struct t_config_option *logger_config_color_backlog_end;
extern struct t_config_option *logger_config_color_backlog_line;
extern struct t_config_option *logger_config_file_auto_log;
+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;
@@ -44,6 +45,8 @@ extern struct t_config_option *logger_config_file_time_format;
extern struct t_config_option *logger_config_get_level (const char *name);
extern int logger_config_set_level (const char *name, const char *value);
extern struct t_config_option *logger_config_get_mask (const char *name);
+extern void logger_config_color_lines_change (const void *pointer, void *data,
+ struct t_config_option *option);
extern int logger_config_init ();
extern int logger_config_read ();
extern int logger_config_write ();
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index a04632186..a41d44dfe 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -51,7 +51,8 @@ WEECHAT_PLUGIN_PRIORITY(14000);
struct t_weechat_plugin *weechat_logger_plugin = NULL;
-struct t_hook *logger_timer = NULL; /* timer to flush log files */
+struct t_hook *logger_hook_timer = NULL; /* timer to flush log files */
+struct t_hook *logger_hook_print = NULL;
/*
@@ -610,7 +611,7 @@ logger_write_line (struct t_logger_buffer *logger_buffer,
if (message)
free (message);
logger_buffer->flush_needed = 1;
- if (!logger_timer)
+ if (!logger_hook_timer)
{
fflush (logger_buffer->log_file);
if (weechat_config_boolean (logger_config_file_fsync))
@@ -1007,8 +1008,9 @@ logger_print_cb (const void *pointer, void *data,
{
struct t_logger_buffer *ptr_logger_buffer;
struct tm *date_tmp;
- char buf_time[256];
- int line_log_level, prefix_is_nick;
+ char buf_time[256], *prefix_ansi, *message_ansi;
+ const char *ptr_prefix, *ptr_message;
+ int line_log_level, prefix_is_nick, color_lines;
/* make C compiler happy */
(void) pointer;
@@ -1018,32 +1020,56 @@ logger_print_cb (const void *pointer, void *data,
logger_get_line_tag_info (tags_count, tags, &line_log_level,
&prefix_is_nick);
- if (line_log_level >= 0)
+ if (line_log_level < 0)
+ return WEECHAT_RC_OK;
+
+ ptr_logger_buffer = logger_buffer_search_buffer (buffer);
+ if (ptr_logger_buffer
+ && ptr_logger_buffer->log_enabled
+ && (date > 0)
+ && (line_log_level <= ptr_logger_buffer->log_level))
{
- ptr_logger_buffer = logger_buffer_search_buffer (buffer);
- if (ptr_logger_buffer
- && ptr_logger_buffer->log_enabled
- && (date > 0)
- && (line_log_level <= ptr_logger_buffer->log_level))
+ prefix_ansi = NULL;
+ message_ansi = NULL;
+ color_lines = weechat_config_boolean (logger_config_file_color_lines);
+ if (color_lines)
{
- buf_time[0] = '\0';
- date_tmp = localtime (&date);
- if (date_tmp)
- {
- if (strftime (buf_time, sizeof (buf_time) - 1,
- weechat_config_string (logger_config_file_time_format),
- date_tmp) == 0)
- buf_time[0] = '\0';
- }
-
- logger_write_line (ptr_logger_buffer,
- "%s\t%s%s%s\t%s",
- buf_time,
- (prefix && prefix_is_nick) ? weechat_config_string (logger_config_file_nick_prefix) : "",
- (prefix) ? prefix : "",
- (prefix && prefix_is_nick) ? weechat_config_string (logger_config_file_nick_suffix) : "",
- message);
+ prefix_ansi = weechat_hook_modifier_exec ("color_encode_ansi",
+ NULL, prefix);
+ message_ansi = weechat_hook_modifier_exec ("color_encode_ansi",
+ NULL, message);
+ ptr_prefix = prefix_ansi;
+ ptr_message = message_ansi;
+ }
+ else
+ {
+ ptr_prefix = prefix;
+ ptr_message = message;
+ }
+ buf_time[0] = '\0';
+ date_tmp = localtime (&date);
+ if (date_tmp)
+ {
+ if (strftime (buf_time, sizeof (buf_time) - 1,
+ weechat_config_string (logger_config_file_time_format),
+ date_tmp) == 0)
+ buf_time[0] = '\0';
}
+
+ logger_write_line (
+ ptr_logger_buffer,
+ "%s\t%s%s%s\t%s%s",
+ buf_time,
+ (ptr_prefix && prefix_is_nick) ? weechat_config_string (logger_config_file_nick_prefix) : "",
+ (ptr_prefix) ? ptr_prefix : "",
+ (ptr_prefix && prefix_is_nick) ? weechat_config_string (logger_config_file_nick_suffix) : "",
+ (color_lines) ? "\x1B[0m" : "",
+ ptr_message);
+
+ if (prefix_ansi)
+ free (prefix_ansi);
+ if (message_ansi)
+ free (message_ansi);
}
return WEECHAT_RC_OK;
@@ -1103,7 +1129,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("day_changed",
&logger_day_changed_signal_cb, NULL, NULL);
- weechat_hook_print (NULL, NULL, NULL, 1, &logger_print_cb, NULL, NULL);
+ logger_config_color_lines_change (NULL, NULL, NULL);
logger_info_init ();
@@ -1120,10 +1146,16 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
/* make C compiler happy */
(void) plugin;
- if (logger_timer)
+ if (logger_hook_print)
+ {
+ weechat_unhook (logger_hook_print);
+ logger_hook_print = NULL;
+ }
+
+ if (logger_hook_timer)
{
- weechat_unhook (logger_timer);
- logger_timer = NULL;
+ weechat_unhook (logger_hook_timer);
+ logger_hook_timer = NULL;
}
logger_config_write ();
diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h
index 472b0512e..008c97888 100644
--- a/src/plugins/logger/logger.h
+++ b/src/plugins/logger/logger.h
@@ -30,7 +30,8 @@ struct t_logger_buffer;
extern struct t_weechat_plugin *weechat_logger_plugin;
-extern struct t_hook *logger_timer;
+extern struct t_hook *logger_hook_timer;
+extern struct t_hook *logger_hook_print;
extern char *logger_build_option_name (struct t_gui_buffer *buffer);
extern void logger_set_log_filename (struct t_logger_buffer *logger_buffer);
@@ -38,6 +39,11 @@ 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_print_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer, time_t date,
+ int tags_count, const char **tags,
+ int displayed, int highlight,
+ const char *prefix, const char *message);
extern int logger_timer_cb (const void *pointer, void *data,
int remaining_calls);