| 171 | */ |
| 172 | |
| 173 | void |
| 174 | _cups_debug_puts(const char *s) /* I - String to output */ |
| 175 | { |
| 176 | struct timeval curtime; /* Current time */ |
| 177 | char buffer[2048]; /* Output buffer */ |
| 178 | ssize_t bytes; /* Number of bytes in buffer */ |
| 179 | int level; /* Log level in message */ |
| 180 | int myerrno = errno;/* Copy of errno value */ |
| 181 | |
| 182 | |
| 183 | /* |
| 184 | * See if we need to do any logging... |
| 185 | */ |
| 186 | |
| 187 | if (!debug_init) |
| 188 | _cups_debug_set(getenv("CUPS_DEBUG_LOG"), getenv("CUPS_DEBUG_LEVEL"), |
| 189 | getenv("CUPS_DEBUG_FILTER"), 0); |
| 190 | |
| 191 | if (_cups_debug_fd < 0) |
| 192 | goto done; |
| 193 | |
| 194 | /* |
| 195 | * Filter as needed... |
| 196 | */ |
| 197 | |
| 198 | if (isdigit(s[0])) |
| 199 | level = *s++ - '0'; |
| 200 | else |
| 201 | level = 0; |
| 202 | |
| 203 | if (level > _cups_debug_level) |
| 204 | goto done; |
| 205 | |
| 206 | if (debug_filter) |
| 207 | { |
| 208 | int result; /* Filter result */ |
| 209 | |
| 210 | _cupsMutexLock(&debug_init_mutex); |
| 211 | result = regexec(debug_filter, s, 0, NULL, 0); |
| 212 | _cupsMutexUnlock(&debug_init_mutex); |
| 213 | |
| 214 | if (result) |
| 215 | goto done; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Format the message... |
| 220 | */ |
| 221 | |
| 222 | gettimeofday(&curtime, NULL); |
| 223 | bytes = snprintf(buffer, sizeof(buffer), "T%03d %02d:%02d:%02d.%03d %s", |
| 224 | debug_thread_id(), (int)((curtime.tv_sec / 3600) % 24), |
| 225 | (int)((curtime.tv_sec / 60) % 60), |
| 226 | (int)(curtime.tv_sec % 60), (int)(curtime.tv_usec / 1000), |
| 227 | s); |
| 228 | |
| 229 | if ((size_t)bytes >= (sizeof(buffer) - 1)) |
| 230 | { |
nothing calls this directly
no test coverage detected