diff options
Diffstat (limited to 'daemon/log.c')
| -rw-r--r-- | daemon/log.c | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/daemon/log.c b/daemon/log.c deleted file mode 100644 index 1973257..0000000 --- a/daemon/log.c +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | /* | ||
| 2 | usbmuxd - iPhone/iPod Touch USB multiplex server daemon | ||
| 3 | |||
| 4 | Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com> | ||
| 5 | Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> | ||
| 6 | |||
| 7 | This program is free software; you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 2 or version 3. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program; if not, write to the Free Software | ||
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | |||
| 20 | */ | ||
| 21 | |||
| 22 | #ifdef HAVE_CONFIG_H | ||
| 23 | #include <config.h> | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #include <stdio.h> | ||
| 27 | #include <stdlib.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <stdarg.h> | ||
| 30 | #include <time.h> | ||
| 31 | #include <sys/time.h> | ||
| 32 | #include <syslog.h> | ||
| 33 | |||
| 34 | #include "log.h" | ||
| 35 | |||
| 36 | int log_level = LL_WARNING; | ||
| 37 | |||
| 38 | int log_syslog = 0; | ||
| 39 | |||
| 40 | void log_enable_syslog() | ||
| 41 | { | ||
| 42 | if (!log_syslog) { | ||
| 43 | openlog("usbmuxd", LOG_PID, 0); | ||
| 44 | log_syslog = 1; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | void log_disable_syslog() | ||
| 49 | { | ||
| 50 | if (log_syslog) { | ||
| 51 | closelog(); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | static int level_to_syslog_level(int level) | ||
| 56 | { | ||
| 57 | int result = level + LOG_CRIT; | ||
| 58 | if (result > LOG_DEBUG) { | ||
| 59 | result = LOG_DEBUG; | ||
| 60 | } | ||
| 61 | return result; | ||
| 62 | } | ||
| 63 | |||
| 64 | void usbmuxd_log(enum loglevel level, const char *fmt, ...) | ||
| 65 | { | ||
| 66 | va_list ap; | ||
| 67 | char *fs; | ||
| 68 | struct timeval ts; | ||
| 69 | struct tm *tp; | ||
| 70 | |||
| 71 | if(level > log_level) | ||
| 72 | return; | ||
| 73 | |||
| 74 | gettimeofday(&ts, NULL); | ||
| 75 | tp = localtime(&ts.tv_sec); | ||
| 76 | |||
| 77 | fs = malloc(20 + strlen(fmt)); | ||
| 78 | |||
| 79 | if(log_syslog) { | ||
| 80 | sprintf(fs, "[%d] %s\n", level, fmt); | ||
| 81 | } else { | ||
| 82 | strftime(fs, 10, "[%H:%M:%S", tp); | ||
| 83 | sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt); | ||
| 84 | } | ||
| 85 | |||
| 86 | va_start(ap, fmt); | ||
| 87 | if (log_syslog) { | ||
| 88 | vsyslog(level_to_syslog_level(level), fs, ap); | ||
| 89 | } else { | ||
| 90 | vfprintf(stderr, fs, ap); | ||
| 91 | } | ||
| 92 | va_end(ap); | ||
| 93 | |||
| 94 | free(fs); | ||
| 95 | } | ||
