r15545 - gnucash/trunk - Support for ~/.gnucash/log.conf, a key-value file of logging settings; see comment-doc for qof_log_parse_log_config(...) for the file format.
Josh Sled
jsled at cvs.gnucash.org
Fri Feb 9 20:29:30 EST 2007
Author: jsled
Date: 2007-02-09 20:29:29 -0500 (Fri, 09 Feb 2007)
New Revision: 15545
Trac: http://svn.gnucash.org/trac/changeset/15545
Modified:
gnucash/trunk/lib/libqof/qof/qoflog.c
gnucash/trunk/lib/libqof/qof/qoflog.h
gnucash/trunk/src/bin/gnucash-bin.c
Log:
Support for ~/.gnucash/log.conf, a key-value file of logging settings; see comment-doc for qof_log_parse_log_config(...) for the file format.
Modified: gnucash/trunk/lib/libqof/qof/qoflog.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qoflog.c 2007-02-10 01:28:10 UTC (rev 15544)
+++ gnucash/trunk/lib/libqof/qof/qoflog.c 2007-02-10 01:29:29 UTC (rev 15545)
@@ -39,6 +39,9 @@
#include <string.h>
#include <sys/time.h>
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "qof.log"
+
#ifndef HAVE_LOCALTIME_R
#include "localtime_r.h"
#endif
@@ -223,6 +226,92 @@
return function_buffer;
}
+void
+qof_log_init_filename_special(const char *log_to_filename)
+{
+ if (g_ascii_strcasecmp("stderr", log_to_filename) == 0)
+ {
+ qof_log_set_file(stderr);
+ }
+ else if (g_ascii_strcasecmp("stdout", log_to_filename) == 0)
+ {
+ qof_log_set_file(stdout);
+ }
+ else
+ {
+ qof_log_init_filename(log_to_filename);
+ }
+}
+
+void
+qof_log_parse_log_config(const char *filename)
+{
+ const gchar *levels_group = "levels", *output_group = "output";
+ GError *err;
+ GKeyFile *conf = g_key_file_new();
+
+ if (!g_key_file_load_from_file(conf, filename, G_KEY_FILE_NONE, &err))
+ {
+ g_warning("unable to parse [%s]: %s", filename, err->message);
+ g_error_free(err);
+ return;
+ }
+
+ g_debug("parsing log config from [%s]", filename);
+ if (g_key_file_has_group(conf, levels_group))
+ {
+ int num_levels;
+ int key_idx;
+ gchar **levels;
+
+ levels = g_key_file_get_keys(conf, levels_group, &num_levels, NULL);
+
+ for (key_idx = 0; key_idx < num_levels && levels[key_idx] != NULL; key_idx++)
+ {
+ QofLogLevel level;
+ gchar *logger_name = NULL, *level_str = NULL;
+
+ logger_name = g_strdup(levels[key_idx]);
+ level_str = g_key_file_get_string(conf, levels_group, logger_name, NULL);
+ level = qof_log_level_from_string(level_str);
+
+ g_debug("setting log [%s] to level [%s=%d]", logger_name, level_str, level);
+ qof_log_set_level(logger_name, level);
+
+ g_free(level_str);
+ }
+ g_strfreev(levels);
+ }
+
+ if (g_key_file_has_group(conf, levels_group))
+ {
+ int num_outputs;
+ int output_idx;
+ gchar **outputs;
+
+ outputs = g_key_file_get_keys(conf, output_group, &num_outputs, NULL);
+ for (output_idx = 0; output_idx < num_outputs && outputs[output_idx] != NULL; output_idx++)
+ {
+ gchar *key = outputs[output_idx];
+ gchar *value;
+
+ if (g_ascii_strcasecmp("to", key) != 0)
+ {
+ g_warning("unknown key [%s] in [outputs], skipping", key);
+ continue;
+ }
+
+ value = g_key_file_get_string(conf, output_group, key, NULL);
+ g_debug("setting [output].to=[%s]", value);
+ qof_log_init_filename_special(value);
+ g_free(value);
+ }
+ g_strfreev(outputs);
+ }
+
+ g_key_file_free(conf);
+}
+
gboolean
qof_log_check(QofLogModule log_domain, QofLogLevel log_level)
{
Modified: gnucash/trunk/lib/libqof/qof/qoflog.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qoflog.h 2007-02-10 01:28:10 UTC (rev 15544)
+++ gnucash/trunk/lib/libqof/qof/qoflog.h 2007-02-10 01:29:29 UTC (rev 15545)
@@ -81,6 +81,26 @@
**/
void qof_log_init_filename (const gchar* logfilename);
+/**
+ * If {@param log_to_filename} is "stderr" or "stdout" (exactly,
+ * case-insensitive), then those special files are used; otherwise, the
+ * literal filename as given, as {@link qof_log_init_filename}.
+ **/
+void qof_log_init_filename_special(const char *log_to_filename);
+
+/** Parse a log-configuration file. A GKeyFile-format file of the schema::
+ *
+ * [levels]
+ * # log.ger.path=level
+ * gnc.engine.sx=debug
+ * gnc.gui.sx=debug
+ * gnc.gui.freqspec=debug
+ * [output]
+ * # to=["stderr"|"stdout"|filename]
+ * to=stderr
+ **/
+void qof_log_parse_log_config(const char *filename);
+
/** Be nice, close the logfile if possible. */
void qof_log_shutdown (void);
Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c 2007-02-10 01:28:10 UTC (rev 15544)
+++ gnucash/trunk/src/bin/gnucash-bin.c 2007-02-10 01:29:29 UTC (rev 15545)
@@ -461,18 +461,7 @@
{
if (log_to_filename != NULL)
{
- if (g_ascii_strcasecmp("stderr", log_to_filename) == 0)
- {
- qof_log_set_file(stderr);
- }
- else if (g_ascii_strcasecmp("stdout", log_to_filename) == 0)
- {
- qof_log_set_file(stdout);
- }
- else
- {
- qof_log_init_filename(log_to_filename);
- }
+ qof_log_init_filename_special(log_to_filename);
}
else
{
@@ -513,6 +502,14 @@
g_strfreev(parts);
}
}
+
+ {
+ gchar *log_config_filename;
+ log_config_filename = gnc_build_dotgnucash_path("log.conf");
+ if (g_file_test(log_config_filename, G_FILE_TEST_EXISTS))
+ qof_log_parse_log_config(log_config_filename);
+ g_free(log_config_filename);
+ }
}
int
More information about the gnucash-changes
mailing list