aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-08-22 14:43:24 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2013-08-22 14:46:10 +0200
commitd3e49c4280f10584587fad83bc08c6a168c174d3 (patch)
tree9127d2f55556a0a049bef296c14da74e0b05904e /src/log.c
parent82ec45bb8abf8052a558e8ad589b66b34a0084fa (diff)
downloadpingu-d3e49c4280f10584587fad83bc08c6a168c174d3.tar.bz2
pingu-d3e49c4280f10584587fad83bc08c6a168c174d3.tar.xz
move soures to src subdir
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..85a32e6
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,72 @@
+/* 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"
+
+static int log_verbose = 0;
+
+void log_init(const char* prefix, int verbose)
+{
+ log_verbose = verbose;
+ openlog(prefix, LOG_PERROR | LOG_PID, LOG_DAEMON);
+}
+
+void log_debug(const char *format, ...)
+{
+ va_list va;
+
+ if (log_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);
+}
+
+void log_warning(const char *format, ...)
+{
+ va_list va;
+
+ va_start(va, format);
+ vsyslog(LOG_WARNING, format, va);
+ va_end(va);
+}