Adedd mcp status log message, added log_allowed function, implemented selective logging
This commit is contained in:
parent
44d940db8b
commit
0d50e92341
|
@ -313,8 +313,8 @@ gm_world_load_input_history(GmWorld *world) {
|
||||||
g_string_free(str, TRUE);
|
g_string_free(str, TRUE);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else {
|
} else {
|
||||||
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.LoadInputHistory: could not retrieve contents of "
|
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.LoadInputHistory: could not "
|
||||||
"file %s (%s)", filename, strerror(errno));
|
"retrieve contents of file %s (%s)", filename, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
|
@ -330,12 +330,13 @@ gm_world_save_input_history(GmWorld *world) {
|
||||||
return;
|
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");
|
f = fopen(filename, "w");
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: saving input history to %s",
|
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: saving input "
|
||||||
filename);
|
"history to %s", filename);
|
||||||
|
|
||||||
for (elem = world->priv->history; elem; elem = elem->next) {
|
for (elem = world->priv->history; elem; elem = elem->next) {
|
||||||
fprintf(f, "%s\n", (gchar *) (elem->data));
|
fprintf(f, "%s\n", (gchar *) (elem->data));
|
||||||
|
@ -345,8 +346,8 @@ gm_world_save_input_history(GmWorld *world) {
|
||||||
|
|
||||||
chmod(filename, 0660);
|
chmod(filename, 0660);
|
||||||
} else {
|
} else {
|
||||||
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: couldn't open history file (%s)"
|
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.SaveInputHistory: couldn't open "
|
||||||
" for saving: %s", filename, strerror(errno));
|
"history file (%s) for saving: %s", filename, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
|
@ -423,8 +424,6 @@ gm_world_load(GmWorld *world) {
|
||||||
|
|
||||||
void
|
void
|
||||||
gm_world_unload(GmWorld *world) {
|
gm_world_unload(GmWorld *world) {
|
||||||
//GList *w;
|
|
||||||
|
|
||||||
if (world->priv->loaded) {
|
if (world->priv->loaded) {
|
||||||
world->priv->loaded = FALSE;
|
world->priv->loaded = FALSE;
|
||||||
gm_world_disconnect(world);
|
gm_world_disconnect(world);
|
||||||
|
@ -518,6 +517,36 @@ gm_world_disconnect(GmWorld *world) {
|
||||||
gm_net_disconnect(world->priv->net);
|
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
|
void
|
||||||
gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
|
gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
|
||||||
GString *s;
|
GString *s;
|
||||||
|
@ -530,6 +559,17 @@ gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
|
||||||
return;
|
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);
|
timer = time(0);
|
||||||
timet = localtime(&timer);
|
timet = localtime(&timer);
|
||||||
|
|
||||||
|
@ -565,14 +605,17 @@ gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
|
||||||
case LOG_OUT:
|
case LOG_OUT:
|
||||||
s = g_string_append_c(s, '>');
|
s = g_string_append_c(s, '>');
|
||||||
break;
|
break;
|
||||||
|
case LOG_STATUS:
|
||||||
|
s = g_string_append_c(s, '#');
|
||||||
|
break;
|
||||||
case LOG_MCP_IN:
|
case LOG_MCP_IN:
|
||||||
s = g_string_append(s, "[MCP] <");
|
s = g_string_append(s, "[MCP] <");
|
||||||
break;
|
break;
|
||||||
case LOG_MCP_OUT:
|
case LOG_MCP_OUT:
|
||||||
s = g_string_append(s, "[MCP] >");
|
s = g_string_append(s, "[MCP] >");
|
||||||
break;
|
break;
|
||||||
case LOG_STATUS:
|
case LOG_MCP_STATUS:
|
||||||
s = g_string_append_c(s, '#');
|
s = g_string_append(s, "[MCP] #");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Reference in New Issue