| 81 | */ |
| 82 | |
| 83 | void |
| 84 | _cups_debug_printf(const char *format, /* I - Printf-style format string */ |
| 85 | ...) /* I - Additional arguments as needed */ |
| 86 | { |
| 87 | va_list ap; /* Pointer to arguments */ |
| 88 | struct timeval curtime; /* Current time */ |
| 89 | char buffer[2048]; /* Output buffer */ |
| 90 | ssize_t bytes; /* Number of bytes in buffer */ |
| 91 | int level; /* Log level in message */ |
| 92 | int myerrno = errno;/* Copy of errno value */ |
| 93 | |
| 94 | |
| 95 | /* |
| 96 | * See if we need to do any logging... |
| 97 | */ |
| 98 | |
| 99 | if (!debug_init) |
| 100 | _cups_debug_set(getenv("CUPS_DEBUG_LOG"), getenv("CUPS_DEBUG_LEVEL"), |
| 101 | getenv("CUPS_DEBUG_FILTER"), 0); |
| 102 | |
| 103 | if (_cups_debug_fd < 0) |
| 104 | goto done; |
| 105 | |
| 106 | /* |
| 107 | * Filter as needed... |
| 108 | */ |
| 109 | |
| 110 | if (isdigit(format[0])) |
| 111 | level = *format++ - '0'; |
| 112 | else |
| 113 | level = 0; |
| 114 | |
| 115 | if (level > _cups_debug_level) |
| 116 | goto done; |
| 117 | |
| 118 | if (debug_filter) |
| 119 | { |
| 120 | int result; /* Filter result */ |
| 121 | |
| 122 | _cupsMutexLock(&debug_init_mutex); |
| 123 | result = regexec(debug_filter, format, 0, NULL, 0); |
| 124 | _cupsMutexUnlock(&debug_init_mutex); |
| 125 | |
| 126 | if (result) |
| 127 | goto done; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Format the message... |
| 132 | */ |
| 133 | |
| 134 | gettimeofday(&curtime, NULL); |
| 135 | snprintf(buffer, sizeof(buffer), "T%03d %02d:%02d:%02d.%03d ", |
| 136 | debug_thread_id(), (int)((curtime.tv_sec / 3600) % 24), |
| 137 | (int)((curtime.tv_sec / 60) % 60), |
| 138 | (int)(curtime.tv_sec % 60), (int)(curtime.tv_usec / 1000)); |
| 139 | |
| 140 | va_start(ap, format); |
no test coverage detected