| 498 | */ |
| 499 | |
| 500 | int /* O - 1 on success, 0 on error */ |
| 501 | cupsdLogClient(cupsd_client_t *con, /* I - Client connection */ |
| 502 | int level, /* I - Log level */ |
| 503 | const char *message, /* I - Printf-style message string */ |
| 504 | ...) /* I - Additional arguments as needed */ |
| 505 | { |
| 506 | int ret; /* Return value */ |
| 507 | va_list ap, ap2; /* Argument pointers */ |
| 508 | char clientmsg[1024]; /* Format string for client message */ |
| 509 | int status; /* Formatting status */ |
| 510 | |
| 511 | |
| 512 | /* |
| 513 | * See if we want to log this message... |
| 514 | */ |
| 515 | |
| 516 | if (TestConfigFile || !ErrorLog) |
| 517 | return (1); |
| 518 | |
| 519 | if (level > LogLevel) |
| 520 | return (1); |
| 521 | |
| 522 | /* |
| 523 | * Format and write the log message... |
| 524 | */ |
| 525 | |
| 526 | _cupsMutexLock(&log_mutex); |
| 527 | |
| 528 | if (con) |
| 529 | snprintf(clientmsg, sizeof(clientmsg), "[Client %d] %s", con->number, |
| 530 | message); |
| 531 | else |
| 532 | strlcpy(clientmsg, message, sizeof(clientmsg)); |
| 533 | |
| 534 | va_start(ap, message); |
| 535 | |
| 536 | do |
| 537 | { |
| 538 | va_copy(ap2, ap); |
| 539 | status = format_log_line(clientmsg, ap2); |
| 540 | va_end(ap2); |
| 541 | } |
| 542 | while (status == 0); |
| 543 | |
| 544 | va_end(ap); |
| 545 | |
| 546 | if (status > 0) |
| 547 | ret = cupsdWriteErrorLog(level, log_line); |
| 548 | else |
| 549 | ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line."); |
| 550 | |
| 551 | _cupsMutexUnlock(&log_mutex); |
| 552 | |
| 553 | return (ret); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | /* |
no test coverage detected