summaryrefslogtreecommitdiffstats
path: root/usbmuxd/log.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-08-16 19:08:56 +0200
committerGravatar Hector Martin2009-08-16 21:50:48 +0200
commita63578e2d71ae304f6f405b5bb491547f43b79ac (patch)
tree9ff375d8c4557430606030a6facd6d93e3ff502e /usbmuxd/log.c
parenta82a04f2c12b5ac5da8f9cb16c17ed4c4f6402a7 (diff)
downloadusbmuxd-a63578e2d71ae304f6f405b5bb491547f43b79ac.tar.gz
usbmuxd-a63578e2d71ae304f6f405b5bb491547f43b79ac.tar.bz2
Implemented option handling providing daemonization, verbosity, and logging to syslog
Diffstat (limited to 'usbmuxd/log.c')
-rw-r--r--usbmuxd/log.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/usbmuxd/log.c b/usbmuxd/log.c
index a70120b..4f67e85 100644
--- a/usbmuxd/log.c
+++ b/usbmuxd/log.c
@@ -28,10 +28,37 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
+#include <syslog.h>
#include "log.h"
-int log_level = LL_INFO;
+int log_level = LL_FATAL;
+
+int log_syslog = 0;
+
+void log_enable_syslog()
+{
+ if (!log_syslog) {
+ openlog("usbmuxd", LOG_PID, 0);
+ log_syslog = 1;
+ }
+}
+
+void log_disable_syslog()
+{
+ if (log_syslog) {
+ closelog();
+ }
+}
+
+static int level_to_syslog_level(int level)
+{
+ int result = level + LOG_CRIT;
+ if (result > LOG_DEBUG) {
+ result = LOG_DEBUG;
+ }
+ return result;
+}
void usbmuxd_log(enum loglevel level, const char *fmt, ...)
{
@@ -51,7 +78,11 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
va_start(ap, fmt);
- vfprintf(stderr, fs, ap);
+ if (log_syslog) {
+ vsyslog(level_to_syslog_level(level), fs, ap);
+ } else {
+ vfprintf(stderr, fs, ap);
+ }
va_end(ap);
free(fs);