mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
Merge pull request #50 from ailin-nemui/gliblog
Improve handling of GLib log messages
(cherry picked from commit 0e3f6aa4a2
)
This commit is contained in:
parent
27046adabe
commit
26c4cd8bbf
@ -6,7 +6,7 @@
|
|||||||
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||||
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
||||||
|
|
||||||
#define IRSSI_ABI_VERSION 42
|
#define IRSSI_ABI_VERSION 43
|
||||||
|
|
||||||
#define DEFAULT_SERVER_ADD_PORT 6667
|
#define DEFAULT_SERVER_ADD_PORT 6667
|
||||||
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
|
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
|
||||||
|
@ -166,6 +166,7 @@ void fe_common_core_init(void)
|
|||||||
settings_add_bool("lookandfeel", "use_msgs_window", FALSE);
|
settings_add_bool("lookandfeel", "use_msgs_window", FALSE);
|
||||||
g_get_charset(&str);
|
g_get_charset(&str);
|
||||||
settings_add_str("lookandfeel", "term_charset", str);
|
settings_add_str("lookandfeel", "term_charset", str);
|
||||||
|
settings_add_str("lookandfeel", "glib_log_domains", "all");
|
||||||
themes_init();
|
themes_init();
|
||||||
theme_register(fecommon_core_formats);
|
theme_register(fecommon_core_formats);
|
||||||
|
|
||||||
@ -257,9 +258,54 @@ void fe_common_core_deinit(void)
|
|||||||
g_log_set_default_handler(logger_old, NULL);
|
g_log_set_default_handler(logger_old, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void i_log_func(const char *log_domain, GLogLevelFlags log_level, const char *message)
|
static gboolean glib_domain_wanted(const char *domain)
|
||||||
{
|
{
|
||||||
const char *reason;
|
const char *domains;
|
||||||
|
char *c, *cur;
|
||||||
|
int len = 0;
|
||||||
|
int print_it = 0; /* -1 for exclude, 0 for undecided, 1 for include */
|
||||||
|
int incl;
|
||||||
|
|
||||||
|
/* Go through each item in glib_log_domains setting to determine whether
|
||||||
|
* or not we want to print message from this domain */
|
||||||
|
domains = settings_get_str("glib_log_domains");
|
||||||
|
c = cur = (char *) domains;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* Advance through the string until we hit a space or the end */
|
||||||
|
while (*cur != '\0' && *cur != ' ') {
|
||||||
|
cur++;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle '-' prefix */
|
||||||
|
incl = 1;
|
||||||
|
if (*c == '-') {
|
||||||
|
incl = -1;
|
||||||
|
c++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we got a valid item, process it */
|
||||||
|
if (len > 0 && (!strncmp(domain, c, len) || !strncasecmp("all", c, len) ||
|
||||||
|
!strncmp("*", c, len)))
|
||||||
|
print_it = incl;
|
||||||
|
|
||||||
|
/* Go past any spaces towards the next item */
|
||||||
|
while (*cur == ' ')
|
||||||
|
cur++;
|
||||||
|
|
||||||
|
/* Move on beyond the item we just handled */
|
||||||
|
c = cur;
|
||||||
|
len = 0;
|
||||||
|
} while (*c != '\0' && print_it != -1);
|
||||||
|
|
||||||
|
return (print_it == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void i_log_func(const char *log_domain, GLogLevelFlags log_level, const char *message)
|
||||||
|
{
|
||||||
|
const char *reason, *domain;
|
||||||
|
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case G_LOG_LEVEL_WARNING:
|
case G_LOG_LEVEL_WARNING:
|
||||||
@ -268,16 +314,33 @@ void i_log_func(const char *log_domain, GLogLevelFlags log_level, const char *me
|
|||||||
case G_LOG_LEVEL_CRITICAL:
|
case G_LOG_LEVEL_CRITICAL:
|
||||||
reason = "critical";
|
reason = "critical";
|
||||||
break;
|
break;
|
||||||
|
case G_LOG_LEVEL_DEBUG:
|
||||||
|
reason = "debug";
|
||||||
|
break;
|
||||||
|
case G_LOG_LEVEL_MESSAGE:
|
||||||
|
reason = "message";
|
||||||
|
break;
|
||||||
|
case G_LOG_LEVEL_INFO:
|
||||||
|
reason = "info";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
reason = "error";
|
reason = "error";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If log_domain parameter is NULL, GLib means to tell us that this is
|
||||||
|
* meant to be some nebulous "default" log domain name. */
|
||||||
|
domain = (log_domain ? log_domain : "default");
|
||||||
|
|
||||||
|
/* Only print the message if we decided to */
|
||||||
|
if (!glib_domain_wanted(domain))
|
||||||
|
return;
|
||||||
|
|
||||||
if (windows == NULL)
|
if (windows == NULL)
|
||||||
fprintf(stderr, "GLib %s: %s\n", reason, message);
|
fprintf(stderr, "GLib (%s) %s: %s\n", domain, reason, message);
|
||||||
else {
|
else {
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_GLIB_ERROR, domain, reason,
|
||||||
TXT_GLIB_ERROR, reason, message);
|
message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ FORMAT_REC fecommon_core_formats[] = {
|
|||||||
{ "config_saved", "Saved configuration to file $0", 1, { 0 } },
|
{ "config_saved", "Saved configuration to file $0", 1, { 0 } },
|
||||||
{ "config_reloaded", "Reloaded configuration", 1, { 0 } },
|
{ "config_reloaded", "Reloaded configuration", 1, { 0 } },
|
||||||
{ "config_modified", "Configuration file was modified since irssi was last started - do you want to overwrite the possible changes?", 1, { 0 } },
|
{ "config_modified", "Configuration file was modified since irssi was last started - do you want to overwrite the possible changes?", 1, { 0 } },
|
||||||
{ "glib_error", "{error $0} $1", 2, { 0, 0 } },
|
{ "glib_error", "{error ($0) $1} $2", 3, { 0, 0, 0 } },
|
||||||
{ "overwrite_config", "Overwrite config (y/N)?", 0 },
|
{ "overwrite_config", "Overwrite config (y/N)?", 0 },
|
||||||
{ "set_title", "[{hilight $0}]", 1, { 0 } },
|
{ "set_title", "[{hilight $0}]", 1, { 0 } },
|
||||||
{ "set_item", "$[-!32]0 %_$1", 2, { 0, 0 } },
|
{ "set_item", "$[-!32]0 %_$1", 2, { 0, 0 } },
|
||||||
|
Loading…
Reference in New Issue
Block a user