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
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <time.h>
+#include <sys/time.h>
#include "log.h"
-int log_level = LOG_SPEW;
+int log_level = LL_SPEW;
void usbmuxd_log(enum loglevel level, const char *fmt, ...)
{
va_list ap;
char *fs;
+ struct timeval ts;
+ struct tm *tp;
- if(level < log_level)
+ gettimeofday(&ts, NULL);
+ tp = localtime(&ts.tv_sec);
+
+ if(level > log_level)
return;
- fs = malloc(10 + strlen(fmt));
- sprintf(fs, "[%d] %s\n", level, fmt);
+ fs = malloc(20 + strlen(fmt));
+ strftime(fs, 10, "[%H:%M:%S", tp);
+ sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
va_start(ap, fmt);
vfprintf(stderr, fs, ap);
va_end(ap);
free(fs);
-} \ No newline at end of file
+}