summaryrefslogtreecommitdiffstats
path: root/usbmuxd/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'usbmuxd/log.c')
-rw-r--r--usbmuxd/log.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/usbmuxd/log.c b/usbmuxd/log.c
new file mode 100644
index 0000000..a70120b
--- /dev/null
+++ b/usbmuxd/log.c
@@ -0,0 +1,58 @@
1/*
2 usbmuxd - iPhone/iPod Touch USB multiplex server daemon
3
4Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 2 or version 3.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19*/
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdarg.h>
29#include <time.h>
30#include <sys/time.h>
31
32#include "log.h"
33
34int log_level = LL_INFO;
35
36void usbmuxd_log(enum loglevel level, const char *fmt, ...)
37{
38 va_list ap;
39 char *fs;
40 struct timeval ts;
41 struct tm *tp;
42
43 gettimeofday(&ts, NULL);
44 tp = localtime(&ts.tv_sec);
45
46 if(level > log_level)
47 return;
48
49 fs = malloc(20 + strlen(fmt));
50 strftime(fs, 10, "[%H:%M:%S", tp);
51 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
52
53 va_start(ap, fmt);
54 vfprintf(stderr, fs, ap);
55 va_end(ap);
56
57 free(fs);
58}