aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--log.c60
-rw-r--r--log.h8
2 files changed, 68 insertions, 0 deletions
diff --git a/log.c b/log.c
new file mode 100644
index 0000000..f105ecd
--- /dev/null
+++ b/log.c
@@ -0,0 +1,60 @@
+/* log.c - Logging via syslog
+ * copied from opennhrp
+ *
+ * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 or later as
+ * published by the Free Software Foundation.
+ *
+ * See http://www.gnu.org/ for details.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+#include <stdarg.h>
+
+#include "pingu.h"
+#include "log.h"
+
+void log_init(void)
+{
+ openlog("pingu", LOG_PERROR | LOG_PID, LOG_DAEMON);
+}
+
+void log_debug(const char *format, ...)
+{
+ va_list va;
+
+ if (pingu_verbose) {
+ va_start(va, format);
+ vsyslog(LOG_DEBUG, format, va);
+ va_end(va);
+ }
+}
+
+void log_perror(const char *message)
+{
+ log_error("%s: %s", message, strerror(errno));
+}
+
+void log_error(const char *format, ...)
+{
+ va_list va;
+
+ va_start(va, format);
+ vsyslog(LOG_ERR, format, va);
+ va_end(va);
+}
+
+void log_info(const char *format, ...)
+{
+ va_list va;
+
+ va_start(va, format);
+ vsyslog(LOG_INFO, format, va);
+ va_end(va);
+}
diff --git a/log.h b/log.h
new file mode 100644
index 0000000..8668dff
--- /dev/null
+++ b/log.h
@@ -0,0 +1,8 @@
+#ifndef LOG_H
+#define LOG_H
+void log_init(void);
+void log_debug(const char *format, ...);
+void log_perror(const char *message);
+void log_error(const char *format, ...);
+void log_info(const char *format, ...);
+#endif