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
28#include <stdarg.h> 28#include <stdarg.h>
29#include <time.h> 29#include <time.h>
30#include <sys/time.h> 30#include <sys/time.h>
31#include <syslog.h>
31 32
32#include "log.h" 33#include "log.h"
33 34
34int log_level = LL_INFO; 35int log_level = LL_FATAL;
36
37int log_syslog = 0;
38
39void log_enable_syslog()
40{
41 if (!log_syslog) {
42 openlog("usbmuxd", LOG_PID, 0);
43 log_syslog = 1;
44 }
45}
46
47void log_disable_syslog()
48{
49 if (log_syslog) {
50 closelog();
51 }
52}
53
54static int level_to_syslog_level(int level)
55{
56 int result = level + LOG_CRIT;
57 if (result > LOG_DEBUG) {
58 result = LOG_DEBUG;
59 }
60 return result;
61}
35 62
36void usbmuxd_log(enum loglevel level, const char *fmt, ...) 63void usbmuxd_log(enum loglevel level, const char *fmt, ...)
37{ 64{
@@ -51,7 +78,11 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
51 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt); 78 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
52 79
53 va_start(ap, fmt); 80 va_start(ap, fmt);
54 vfprintf(stderr, fs, ap); 81 if (log_syslog) {
82 vsyslog(level_to_syslog_level(level), fs, ap);
83 } else {
84 vfprintf(stderr, fs, ap);
85 }
55 va_end(ap); 86 va_end(ap);
56 87
57 free(fs); 88 free(fs);