From 0d50e92341e80d857ed6dac2a6808923e1a1e3e3 Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Fri, 23 Dec 2005 16:10:11 +0000 Subject: [PATCH] Adedd mcp status log message, added log_allowed function, implemented selective logging --- gnoemoe/gm-world.c | 67 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/gnoemoe/gm-world.c b/gnoemoe/gm-world.c index fea44df..8c31cdc 100644 --- a/gnoemoe/gm-world.c +++ b/gnoemoe/gm-world.c @@ -313,8 +313,8 @@ gm_world_load_input_history(GmWorld *world) { g_string_free(str, TRUE); fclose(f); } else { - gm_debug_msg(DEBUG_DEFAULT, "GmWorld.LoadInputHistory: could not retrieve contents of " - "file %s (%s)", filename, strerror(errno)); + gm_debug_msg(DEBUG_DEFAULT, "GmWorld.LoadInputHistory: could not " + "retrieve contents of file %s (%s)", filename, strerror(errno)); } g_free(filename); @@ -330,12 +330,13 @@ gm_world_save_input_history(GmWorld *world) { return; } - filename = g_strconcat(world->priv->path, G_DIR_SEPARATOR_S, "history", NULL); + filename = g_strconcat(world->priv->path, G_DIR_SEPARATOR_S, "history", + NULL); f = fopen(filename, "w"); - + if (f) { - gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: saving input history to %s", - filename); + gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: saving input " + "history to %s", filename); for (elem = world->priv->history; elem; elem = elem->next) { fprintf(f, "%s\n", (gchar *) (elem->data)); @@ -345,8 +346,8 @@ gm_world_save_input_history(GmWorld *world) { chmod(filename, 0660); } else { - gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: couldn't open history file (%s)" - " for saving: %s", filename, strerror(errno)); + gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: couldn't open " + "history file (%s) for saving: %s", filename, strerror(errno)); } g_free(filename); @@ -423,8 +424,6 @@ gm_world_load(GmWorld *world) { void gm_world_unload(GmWorld *world) { - //GList *w; - if (world->priv->loaded) { world->priv->loaded = FALSE; gm_world_disconnect(world); @@ -518,6 +517,36 @@ gm_world_disconnect(GmWorld *world) { gm_net_disconnect(world->priv->net); } +gboolean +gm_world_log_allowed(GmLogType type) { + GmOptions *options = gm_app_options(gm_app_instance()); + // TODO: this can be optimized + + switch (type) { + case LOG_IN: + return gm_options_get_int(options, "logging_in"); + break; + case LOG_OUT: + return gm_options_get_int(options, "logging_out"); + break; + case LOG_STATUS: + return gm_options_get_int(options, "logging_status"); + break; + case LOG_MCP_IN: + return gm_options_get_int(options, "logging_mcp_in"); + break; + case LOG_MCP_OUT: + return gm_options_get_int(options, "logging_mcp_out"); + break; + case LOG_MCP_STATUS: + return gm_options_get_int(options, "logging_mcp_status"); + break; + default: + return FALSE; + break; + } +} + void gm_world_log(GmWorld *world, GmLogType type, gchar *text) { GString *s; @@ -530,6 +559,17 @@ gm_world_log(GmWorld *world, GmLogType type, gchar *text) { return; } + // Check whether to log at all + if (!gm_options_get_int(gm_app_options(gm_app_instance()), + "logging_enable")) { + return; + } + + // Check whether to log this type + if (!gm_world_log_allowed(type)) { + return; + } + timer = time(0); timet = localtime(&timer); @@ -565,14 +605,17 @@ gm_world_log(GmWorld *world, GmLogType type, gchar *text) { case LOG_OUT: s = g_string_append_c(s, '>'); break; + case LOG_STATUS: + s = g_string_append_c(s, '#'); + break; case LOG_MCP_IN: s = g_string_append(s, "[MCP] <"); break; case LOG_MCP_OUT: s = g_string_append(s, "[MCP] >"); break; - case LOG_STATUS: - s = g_string_append_c(s, '#'); + case LOG_MCP_STATUS: + s = g_string_append(s, "[MCP] #"); break; default: break;