summaryrefslogtreecommitdiffstats
path: root/log.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-04-28 02:02:55 +0200
committerGravatar Hector Martin2009-04-28 02:02:55 +0200
commitcc9e6a2318352a8fd3a35c25fcb294331ff54288 (patch)
tree75b891a06a7eddf9674327ae387784b0c64967b0 /log.c
parentd982007a7350df35c5aeba820a520779694514a7 (diff)
downloadusbmuxd-cc9e6a2318352a8fd3a35c25fcb294331ff54288.tar.gz
usbmuxd-cc9e6a2318352a8fd3a35c25fcb294331ff54288.tar.bz2
USB mostly complete, main loop added, polls for devices
Diffstat (limited to 'log.c')
-rw-r--r--log.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/log.c b/log.c
index d7f57df..29b3506 100644
--- a/log.c
+++ b/log.c
@@ -26,25 +26,33 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26#include <stdlib.h> 26#include <stdlib.h>
27#include <string.h> 27#include <string.h>
28#include <stdarg.h> 28#include <stdarg.h>
29#include <time.h>
30#include <sys/time.h>
29 31
30#include "log.h" 32#include "log.h"
31 33
32int log_level = LOG_SPEW; 34int log_level = LL_SPEW;
33 35
34void usbmuxd_log(enum loglevel level, const char *fmt, ...) 36void usbmuxd_log(enum loglevel level, const char *fmt, ...)
35{ 37{
36 va_list ap; 38 va_list ap;
37 char *fs; 39 char *fs;
40 struct timeval ts;
41 struct tm *tp;
38 42
39 if(level < log_level) 43 gettimeofday(&ts, NULL);
44 tp = localtime(&ts.tv_sec);
45
46 if(level > log_level)
40 return; 47 return;
41 48
42 fs = malloc(10 + strlen(fmt)); 49 fs = malloc(20 + strlen(fmt));
43 sprintf(fs, "[%d] %s\n", level, fmt); 50 strftime(fs, 10, "[%H:%M:%S", tp);
51 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
44 52
45 va_start(ap, fmt); 53 va_start(ap, fmt);
46 vfprintf(stderr, fs, ap); 54 vfprintf(stderr, fs, ap);
47 va_end(ap); 55 va_end(ap);
48 56
49 free(fs); 57 free(fs);
50} \ No newline at end of file 58}