diff options
Diffstat (limited to 'log.c')
| -rw-r--r-- | log.c | 18 |
1 files changed, 13 insertions, 5 deletions
| @@ -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 | ||
| 32 | int log_level = LOG_SPEW; | 34 | int log_level = LL_SPEW; |
| 33 | 35 | ||
| 34 | void usbmuxd_log(enum loglevel level, const char *fmt, ...) | 36 | void 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 | } |
