1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

/LOG OPEN -color, /SET awaylog_colors - specifies that the color codes

should be written to log file.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1742 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-08-13 13:51:49 +00:00 committed by cras
parent 08b9062028
commit 4e3b1bba62
4 changed files with 77 additions and 19 deletions
src
core
fe-common/core

View File

@ -184,6 +184,7 @@ static void log_rotate_check(LOG_REC *log)
void log_write_rec(LOG_REC *log, const char *str, int level) void log_write_rec(LOG_REC *log, const char *str, int level)
{ {
char *colorstr;
struct tm *tm; struct tm *tm;
time_t now; time_t now;
int hour, day; int hour, day;
@ -215,6 +216,11 @@ void log_write_rec(LOG_REC *log, const char *str, int level)
log->last = now; log->last = now;
if (log->colorizer == NULL)
colorstr = NULL;
else
str = colorstr = log->colorizer(str);
if ((level & MSGLEVEL_LASTLOG) == 0) if ((level & MSGLEVEL_LASTLOG) == 0)
log_write_timestamp(log->handle, log_timestamp, str, now); log_write_timestamp(log->handle, log_timestamp, str, now);
else else
@ -222,6 +228,8 @@ void log_write_rec(LOG_REC *log, const char *str, int level)
write_buffer(log->handle, "\n", 1); write_buffer(log->handle, "\n", 1);
signal_emit("log written", 2, log, str); signal_emit("log written", 2, log, str);
g_free_not_null(colorstr);
} }
LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item, LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
@ -344,6 +352,8 @@ static void log_update_config(LOG_REC *log)
if (log->items != NULL) if (log->items != NULL)
log_items_update_config(log, node); log_items_update_config(log, node);
signal_emit("log config save", 2, log, node);
} }
static void log_remove_config(LOG_REC *log) static void log_remove_config(LOG_REC *log)
@ -515,6 +525,8 @@ static void log_read_config(void)
log->autoopen = config_node_get_bool(node, "auto_open", FALSE); log->autoopen = config_node_get_bool(node, "auto_open", FALSE);
log->level = level2bits(config_node_get_str(node, "level", 0)); log->level = level2bits(config_node_get_str(node, "level", 0));
signal_emit("log config read", 2, log, node);
node = config_node_section(node, "items", -1); node = config_node_section(node, "items", -1);
if (node != NULL) if (node != NULL)
log_items_read_config(node, log); log_items_read_config(node, log);
@ -549,9 +561,9 @@ void log_init(void)
"--- Day changed %a %b %d %Y"); "--- Day changed %a %b %d %Y");
read_settings(); read_settings();
log_read_config();
signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("setup changed", (SIGNAL_FUNC) read_settings);
signal_add("setup reread", (SIGNAL_FUNC) log_read_config); signal_add("setup reread", (SIGNAL_FUNC) log_read_config);
signal_add("irssi init finished", (SIGNAL_FUNC) log_read_config);
} }
void log_deinit(void) void log_deinit(void)
@ -563,4 +575,5 @@ void log_deinit(void)
signal_remove("setup changed", (SIGNAL_FUNC) read_settings); signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
signal_remove("setup reread", (SIGNAL_FUNC) log_read_config); signal_remove("setup reread", (SIGNAL_FUNC) log_read_config);
signal_remove("irssi init finished", (SIGNAL_FUNC) log_read_config);
} }

View File

@ -6,6 +6,8 @@ enum {
LOG_ITEM_WINDOW_REFNUM LOG_ITEM_WINDOW_REFNUM
}; };
typedef char *(*COLORIZE_FUNC)(const char *str);
typedef struct { typedef struct {
int type; int type;
char *name; char *name;
@ -22,6 +24,7 @@ typedef struct {
GSList *items; /* log only on these items */ GSList *items; /* log only on these items */
time_t last; /* when last message was written */ time_t last; /* when last message was written */
COLORIZE_FUNC colorizer;
unsigned int autoopen:1; /* automatically start logging at startup */ unsigned int autoopen:1; /* automatically start logging at startup */
unsigned int failed:1; /* opening log failed last time */ unsigned int failed:1; /* opening log failed last time */

View File

@ -28,6 +28,7 @@
#include "log.h" #include "log.h"
#include "special-vars.h" #include "special-vars.h"
#include "settings.h" #include "settings.h"
#include "lib-config/iconfig.h"
#include "fe-windows.h" #include "fe-windows.h"
#include "window-items.h" #include "window-items.h"
@ -48,6 +49,11 @@ static THEME_REC *log_theme;
static int skip_next_printtext; static int skip_next_printtext;
static const char *log_theme_name; static const char *log_theme_name;
static char *log_colorizer_strip(const char *str)
{
return strip_codes(str);
}
static void log_add_targets(LOG_REC *log, const char *targets, const char *tag) static void log_add_targets(LOG_REC *log, const char *targets, const char *tag)
{ {
char **tmp, **items; char **tmp, **items;
@ -64,7 +70,8 @@ static void log_add_targets(LOG_REC *log, const char *targets, const char *tag)
} }
/* SYNTAX: LOG OPEN [-noopen] [-autoopen] [-window] [-<server tag>] /* SYNTAX: LOG OPEN [-noopen] [-autoopen] [-window] [-<server tag>]
[-targets <targets>] <fname> [<levels>] */ [-targets <targets>] [-mirccolors | -ansicolors]
<fname> [<levels>] */
static void cmd_log_open(const char *data) static void cmd_log_open(const char *data)
{ {
SERVER_REC *server; SERVER_REC *server;
@ -102,6 +109,9 @@ static void cmd_log_open(const char *data)
if (g_hash_table_lookup(optlist, "autoopen")) if (g_hash_table_lookup(optlist, "autoopen"))
log->autoopen = TRUE; log->autoopen = TRUE;
if (g_hash_table_lookup(optlist, "colors") == NULL)
log->colorizer = log_colorizer_strip;
log_update(log); log_update(log);
if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) { if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
@ -448,7 +458,9 @@ static void log_single_line(WINDOW_REC *window, void *server,
ltoa(windownum, window->refnum); ltoa(windownum, window->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, log = logs_find_item(LOG_ITEM_WINDOW_REFNUM,
windownum, NULL, NULL); windownum, NULL, NULL);
if (log != NULL) log_write_rec(log, text, level); if (log != NULL) {
log_write_rec(log, text, level);
}
if (target == NULL) if (target == NULL)
log_file_write(server, NULL, level, text, FALSE); log_file_write(server, NULL, level, text, FALSE);
@ -492,13 +504,13 @@ static void sig_printtext(TEXT_DEST_REC *dest, const char *text,
} }
log_line(dest->window, dest->server, dest->target, log_line(dest->window, dest->server, dest->target,
dest->level, stripped); dest->level, text);
} }
static void sig_print_format(THEME_REC *theme, const char *module, static void sig_print_format(THEME_REC *theme, const char *module,
TEXT_DEST_REC *dest, void *formatnum, char **args) TEXT_DEST_REC *dest, void *formatnum, char **args)
{ {
char *str, *stripped, *linestart, *tmp; char *str, *linestart, *tmp;
if (log_theme == NULL) { if (log_theme == NULL) {
/* theme isn't loaded for some reason (/reload destroys it), /* theme isn't loaded for some reason (/reload destroys it),
@ -523,10 +535,8 @@ static void sig_print_format(THEME_REC *theme, const char *module,
g_free(tmp); g_free(tmp);
/* strip colors from text, log it. */ /* strip colors from text, log it. */
stripped = strip_codes(str);
log_line(dest->window, dest->server, dest->target, log_line(dest->window, dest->server, dest->target,
dest->level, stripped); dest->level, str);
g_free(stripped);
} }
g_free(str); g_free(str);
@ -584,6 +594,27 @@ static void sig_log_create_failed(LOG_REC *log)
TXT_LOG_CREATE_FAILED, log->fname, g_strerror(errno)); TXT_LOG_CREATE_FAILED, log->fname, g_strerror(errno));
} }
static void sig_log_new(LOG_REC *log)
{
if (!settings_get_bool("awaylog_colors") &&
strcmp(log->fname, settings_get_str("awaylog_file")) == 0)
log->colorizer = log_colorizer_strip;
}
static void sig_log_config_read(LOG_REC *log, CONFIG_NODE *node)
{
if (!config_node_get_bool(node, "colors", FALSE))
log->colorizer = log_colorizer_strip;
}
static void sig_log_config_save(LOG_REC *log, CONFIG_NODE *node)
{
if (log->colorizer == NULL)
iconfig_node_set_bool(node, "colors", TRUE);
else
iconfig_node_set_str(node, "colors", NULL);
}
static void sig_awaylog_show(LOG_REC *log, gpointer pmsgs, gpointer pfilepos) static void sig_awaylog_show(LOG_REC *log, gpointer pmsgs, gpointer pfilepos)
{ {
char *str; char *str;
@ -638,6 +669,7 @@ void fe_log_init(void)
autoremove_tag = g_timeout_add(60000, (GSourceFunc) sig_autoremove, NULL); autoremove_tag = g_timeout_add(60000, (GSourceFunc) sig_autoremove, NULL);
skip_next_printtext = FALSE; skip_next_printtext = FALSE;
settings_add_bool("log", "awaylog_colors", TRUE);
settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log"); settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log");
settings_add_str("log", "autolog_level", "all -crap -clientcrap -ctcps"); settings_add_str("log", "autolog_level", "all -crap -clientcrap -ctcps");
settings_add_bool("log", "autolog", FALSE); settings_add_bool("log", "autolog", FALSE);
@ -660,11 +692,14 @@ void fe_log_init(void)
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_add("log locked", (SIGNAL_FUNC) sig_log_locked); signal_add("log locked", (SIGNAL_FUNC) sig_log_locked);
signal_add("log create failed", (SIGNAL_FUNC) sig_log_create_failed); signal_add("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
signal_add("log new", (SIGNAL_FUNC) sig_log_new);
signal_add("log config read", (SIGNAL_FUNC) sig_log_config_read);
signal_add("log config save", (SIGNAL_FUNC) sig_log_config_save);
signal_add("awaylog show", (SIGNAL_FUNC) sig_awaylog_show); signal_add("awaylog show", (SIGNAL_FUNC) sig_awaylog_show);
signal_add("theme destroyed", (SIGNAL_FUNC) sig_theme_destroyed); signal_add("theme destroyed", (SIGNAL_FUNC) sig_theme_destroyed);
signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("setup changed", (SIGNAL_FUNC) read_settings);
command_set_options("log open", "noopen autoopen -targets window"); command_set_options("log open", "noopen autoopen -targets window colors");
} }
void fe_log_deinit(void) void fe_log_deinit(void)
@ -686,6 +721,9 @@ void fe_log_deinit(void)
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_remove("log locked", (SIGNAL_FUNC) sig_log_locked); signal_remove("log locked", (SIGNAL_FUNC) sig_log_locked);
signal_remove("log create failed", (SIGNAL_FUNC) sig_log_create_failed); signal_remove("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
signal_remove("log new", (SIGNAL_FUNC) sig_log_new);
signal_remove("log config read", (SIGNAL_FUNC) sig_log_config_read);
signal_remove("log config save", (SIGNAL_FUNC) sig_log_config_save);
signal_remove("awaylog show", (SIGNAL_FUNC) sig_awaylog_show); signal_remove("awaylog show", (SIGNAL_FUNC) sig_awaylog_show);
signal_remove("theme destroyed", (SIGNAL_FUNC) sig_theme_destroyed); signal_remove("theme destroyed", (SIGNAL_FUNC) sig_theme_destroyed);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings); signal_remove("setup changed", (SIGNAL_FUNC) read_settings);

View File

@ -653,11 +653,11 @@ void format_newline(WINDOW_REC *window)
} }
/* parse ANSI color string */ /* parse ANSI color string */
static char *get_ansi_color(THEME_REC *theme, char *str, static const char *get_ansi_color(THEME_REC *theme, const char *str,
int *fg_ret, int *bg_ret, int *flags_ret) int *fg_ret, int *bg_ret, int *flags_ret)
{ {
static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
char *start; const char *start;
int fg, bg, flags, num; int fg, bg, flags, num;
if (*str != '[') if (*str != '[')
@ -844,7 +844,10 @@ char *strip_codes(const char *input)
p += 2; p += 2;
continue; continue;
} }
} }
if (*p == 27 && p[1] != '\0')
p = get_ansi_color(current_theme, p, NULL, NULL, NULL);
if (!IS_COLOR_CODE(*p)) if (!IS_COLOR_CODE(*p))
*out++ = *p; *out++ = *p;
@ -975,12 +978,13 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
break; break;
case 27: case 27:
/* ansi color code */ /* ansi color code */
ptr = get_ansi_color(dest->window == NULL || dest->window->theme == NULL ? ptr = (char *)
current_theme : dest->window->theme, get_ansi_color(dest->window == NULL || dest->window->theme == NULL ?
ptr, current_theme : dest->window->theme,
hide_text_style ? NULL : &fgcolor, ptr,
hide_text_style ? NULL : &bgcolor, hide_text_style ? NULL : &fgcolor,
hide_text_style ? NULL : &flags); hide_text_style ? NULL : &bgcolor,
hide_text_style ? NULL : &flags);
break; break;
} }