#include <ctype.h>
#include <string.h>
+#include <glib.h>
+
#include <mysql/mysql.h>
#include "dbstore.h"
(void)strftime(tstr, sizeof(tstr), "%Y-%m-%d %H:%M:%S", &tm);
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, host, user, pass, dbnm, 0, NULL, 0)) {
- fprintf(stderr, "mysql connect error: %s\n",
- mysql_error(&mysql));
+ g_warning("mysql connect error: %s\n", mysql_error(&mysql));
return 1;
}
snprintf(statement, sizeof(statement),
table, tstr, val);
rc = mysql_query(&mysql, statement);
if (rc)
- fprintf(stderr, "mysql insert \"%s\" error: %s\n",
- statement, mysql_error(&mysql));
+ g_warning("mysql insert \"%s\" error: %s\n",
+ statement, mysql_error(&mysql));
mysql_close(&mysql);
return rc;
}
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
+#include <syslog.h>
#include <glib.h>
{ NULL },
};
+void local_log_handler(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer log_context)
+{
+ int syslog_level;
+
+ switch (log_level) {
+ case G_LOG_LEVEL_CRITICAL: syslog_level = LOG_CRIT; break;
+ case G_LOG_LEVEL_ERROR: syslog_level = LOG_ERR; break;
+ case G_LOG_LEVEL_WARNING: syslog_level = LOG_WARNING; break;
+ case G_LOG_LEVEL_MESSAGE: syslog_level = LOG_NOTICE; break;
+ case G_LOG_LEVEL_INFO: syslog_level = LOG_INFO; break;
+ case G_LOG_LEVEL_DEBUG: syslog_level = LOG_DEBUG; break;
+ default: syslog_level = LOG_INFO;
+ }
+ if (!log_domain || (log_domain[0] == '\0'))
+ syslog(syslog_level, "%s", message);
+ else
+ syslog(syslog_level, "%s: %s", log_domain, message);
+}
+
static gboolean channel_watcher(GIOChannel *chan, GIOCondition cond,
gpointer user_data)
{
gboolean got_error = FALSE;
g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
- | G_LOG_FLAG_RECURSION, g_log_default_handler, NULL);
+ | G_LOG_FLAG_RECURSION, local_log_handler, NULL);
opt_dst_type = g_strdup("public");
opt_sec_level = g_strdup("low");
opt_dbconffile = g_strdup("/etc/pulsecounter.db");