2 * "$Id: log.c 9949 2011-08-31 04:58:33Z mike $"
4 * Log file routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdCheckLogFile() - Open/rotate a log file if it needs it.
18 * cupsdGetDateTime() - Returns a pointer to a date/time string.
19 * cupsdLogGSSMessage() - Log a GSSAPI error...
20 * cupsdLogJob() - Log a job message.
21 * cupsdLogMessage() - Log a message to the error log file.
22 * cupsdLogPage() - Log a page to the page log file.
23 * cupsdLogRequest() - Log an HTTP request in Common Log Format.
24 * cupsdWriteErrorLog() - Write a line to the ErrorLog.
25 * format_log_line() - Format a line for a log file.
29 * Include necessary headers...
42 static int log_linesize = 0; /* Size of line for output file */
43 static char *log_line = NULL; /* Line for output file */
50 static int format_log_line(const char *message, va_list ap);
54 * 'cupsdCheckLogFile()' - Open/rotate a log file if it needs it.
57 int /* O - 1 if log file open */
58 cupsdCheckLogFile(cups_file_t **lf, /* IO - Log file */
59 const char *logname) /* I - Log filename */
61 char backname[1024], /* Backup log filename */
62 filename[1024], /* Formatted log filename */
63 *ptr; /* Pointer into filename */
64 const char *logptr; /* Pointer into log filename */
65 struct group *loggrp; /* Group entry of log filename */
69 * See if we have a log file to check...
72 if (!lf || !logname || !logname[0])
76 * Use adm group if possible, fall back to Group
78 loggrp = getgrnam("adm");
81 * Format the filename as needed...
85 (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
89 * Handle format strings...
92 filename[sizeof(filename) - 1] = '\0';
94 if (logname[0] != '/')
96 strlcpy(filename, ServerRoot, sizeof(filename));
97 strlcat(filename, "/", sizeof(filename));
102 for (logptr = logname, ptr = filename + strlen(filename);
103 *logptr && ptr < (filename + sizeof(filename) - 1);
115 * Insert the server name...
118 strlcpy(ptr, ServerName, sizeof(filename) - (ptr - filename));
124 * Otherwise just insert the character...
137 * See if the log file is open...
143 * Nope, open the log file...
146 if ((*lf = cupsFileOpen(filename, "a")) == NULL)
149 * If the file is in CUPS_LOGDIR then try to create a missing directory...
152 if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR)))
155 * Try updating the permissions of the containing log directory, using
156 * the log file permissions as a basis...
159 int log_dir_perm = 0300 | LogFilePerm;
160 /* LogFilePerm + owner write/search */
161 if (log_dir_perm & 0040)
162 log_dir_perm |= 0010; /* Add group search */
163 if (log_dir_perm & 0004)
164 log_dir_perm |= 0001; /* Add other search */
166 cupsdCheckPermissions(CUPS_LOGDIR, NULL, log_dir_perm, RunUser, Group,
169 *lf = cupsFileOpen(filename, "a");
174 syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
177 if (FatalErrors & CUPSD_FATAL_LOG)
178 cupsdEndProcess(getpid(), 0);
184 if (strncmp(filename, "/dev/", 5))
187 * Change ownership and permissions of non-device logs...
190 fchown(cupsFileNumber(*lf), RunUser, loggrp ? loggrp->gr_gid : Group);
191 fchmod(cupsFileNumber(*lf), LogFilePerm);
196 * Do we need to rotate the log?
199 if (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
208 strcpy(backname, filename);
209 strlcat(backname, ".O", sizeof(backname));
212 rename(filename, backname);
214 if ((*lf = cupsFileOpen(filename, "a")) == NULL)
216 syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
219 if (FatalErrors & CUPSD_FATAL_LOG)
220 cupsdEndProcess(getpid(), 0);
226 * Change ownership and permissions of non-device logs...
229 fchown(cupsFileNumber(*lf), RunUser, loggrp ? loggrp->gr_gid : Group);
230 fchmod(cupsFileNumber(*lf), LogFilePerm);
238 * 'cupsdGetDateTime()' - Returns a pointer to a date/time string.
241 char * /* O - Date/time string */
242 cupsdGetDateTime(struct timeval *t, /* I - Time value or NULL for current */
243 cupsd_time_t format) /* I - Format to use */
245 struct timeval curtime; /* Current time value */
246 struct tm *date; /* Date/time value */
247 static struct timeval last_time = { 0, 0 };
248 /* Last time we formatted */
249 static char s[1024]; /* Date/time string */
250 static const char * const months[12] =/* Months */
268 * Make sure we have a valid time...
273 gettimeofday(&curtime, NULL);
277 if (t->tv_sec != last_time.tv_sec ||
278 (LogTimeFormat == CUPSD_TIME_USECS && t->tv_usec != last_time.tv_usec))
283 * Get the date and time from the UNIX time value, and then format it
284 * into a string. Note that we *can't* use the strftime() function since
285 * it is localized and will seriously confuse automatic programs if the
286 * month names are in the wrong language!
288 * Also, we use the "timezone" variable that contains the current timezone
289 * offset from GMT in seconds so that we are reporting local time in the
290 * log files. If you want GMT, set the TZ environment variable accordingly
291 * before starting the scheduler.
293 * (*BSD and Darwin store the timezone offset in the tm structure)
296 date = localtime(&(t->tv_sec));
298 if (format == CUPSD_TIME_STANDARD)
299 snprintf(s, sizeof(s), "[%02d/%s/%04d:%02d:%02d:%02d %+03ld%02ld]",
300 date->tm_mday, months[date->tm_mon], 1900 + date->tm_year,
301 date->tm_hour, date->tm_min, date->tm_sec,
302 #ifdef HAVE_TM_GMTOFF
303 date->tm_gmtoff / 3600, (date->tm_gmtoff / 60) % 60);
305 timezone / 3600, (timezone / 60) % 60);
306 #endif /* HAVE_TM_GMTOFF */
308 snprintf(s, sizeof(s), "[%02d/%s/%04d:%02d:%02d:%02d.%06d %+03ld%02ld]",
309 date->tm_mday, months[date->tm_mon], 1900 + date->tm_year,
310 date->tm_hour, date->tm_min, date->tm_sec, (int)t->tv_usec,
311 #ifdef HAVE_TM_GMTOFF
312 date->tm_gmtoff / 3600, (date->tm_gmtoff / 60) % 60);
314 timezone / 3600, (timezone / 60) % 60);
315 #endif /* HAVE_TM_GMTOFF */
323 * 'cupsdLogFCMessage()' - Log a file checking message.
328 void *context, /* I - Printer (if any) */
329 _cups_fc_result_t result, /* I - Check result */
330 const char *message) /* I - Message to log */
332 cupsd_printer_t *p = (cupsd_printer_t *)context;
334 cupsd_loglevel_t level; /* Log level */
337 if (result == _CUPS_FILE_CHECK_OK)
338 level = CUPSD_LOG_DEBUG2;
340 level = CUPSD_LOG_ERROR;
344 cupsdLogMessage(level, "%s: %s", p->name, message);
346 if (result == _CUPS_FILE_CHECK_MISSING ||
347 result == _CUPS_FILE_CHECK_WRONG_TYPE)
349 strlcpy(p->state_message, message, sizeof(p->state_message));
351 if (cupsdSetPrinterReasons(p, "+cups-missing-filter-warning"))
352 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, p, NULL, "%s", message);
354 else if (result == _CUPS_FILE_CHECK_PERMISSIONS ||
355 result == _CUPS_FILE_CHECK_RELATIVE_PATH)
357 strlcpy(p->state_message, message, sizeof(p->state_message));
359 if (cupsdSetPrinterReasons(p, "+cups-insecure-filter-warning"))
360 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, p, NULL, "%s", message);
364 cupsdLogMessage(level, "%s", message);
370 * 'cupsdLogGSSMessage()' - Log a GSSAPI error...
373 int /* O - 1 on success, 0 on error */
375 int level, /* I - Log level */
376 int major_status, /* I - Major GSSAPI status */
377 int minor_status, /* I - Minor GSSAPI status */
378 const char *message, /* I - printf-style message string */
379 ...) /* I - Additional args as needed */
381 OM_uint32 err_major_status, /* Major status code for display */
382 err_minor_status; /* Minor status code for display */
383 OM_uint32 msg_ctx; /* Message context */
384 gss_buffer_desc major_status_string = GSS_C_EMPTY_BUFFER,
385 /* Major status message */
386 minor_status_string = GSS_C_EMPTY_BUFFER;
387 /* Minor status message */
388 int ret; /* Return value */
392 err_major_status = gss_display_status(&err_minor_status,
397 &major_status_string);
399 if (!GSS_ERROR(err_major_status))
400 gss_display_status(&err_minor_status, minor_status, GSS_C_MECH_CODE,
401 GSS_C_NULL_OID, &msg_ctx, &minor_status_string);
403 ret = cupsdLogMessage(level, "%s: %s, %s", message,
404 (char *)major_status_string.value,
405 (char *)minor_status_string.value);
406 gss_release_buffer(&err_minor_status, &major_status_string);
407 gss_release_buffer(&err_minor_status, &minor_status_string);
411 #endif /* HAVE_GSSAPI */
415 * 'cupsdLogJob()' - Log a job message.
418 int /* O - 1 on success, 0 on error */
419 cupsdLogJob(cupsd_job_t *job, /* I - Job */
420 int level, /* I - Log level */
421 const char *message, /* I - Printf-style message string */
422 ...) /* I - Additional arguments as needed */
424 va_list ap; /* Argument pointer */
425 char jobmsg[1024]; /* Format string for job message */
426 int status; /* Formatting status */
430 * See if we want to log this message...
433 if (TestConfigFile || !ErrorLog)
436 if ((level > LogLevel ||
437 (level == CUPSD_LOG_INFO && LogLevel < CUPSD_LOG_DEBUG)) &&
438 LogDebugHistory <= 0)
442 * Format and write the log message...
445 snprintf(jobmsg, sizeof(jobmsg), "[Job %d] %s", job->id, message);
449 va_start(ap, message);
450 status = format_log_line(jobmsg, ap);
457 if ((level > LogLevel ||
458 (level == CUPSD_LOG_INFO && LogLevel < CUPSD_LOG_DEBUG)) &&
462 * Add message to the job history...
465 cupsd_joblog_t *temp; /* Copy of log message */
468 if ((temp = malloc(sizeof(cupsd_joblog_t) + strlen(log_line))) != NULL)
470 temp->time = time(NULL);
471 strcpy(temp->message, log_line);
475 job->history = cupsArrayNew(NULL, NULL);
477 if (job->history && temp)
479 cupsArrayAdd(job->history, temp);
481 if (cupsArrayCount(job->history) > LogDebugHistory)
484 * Remove excess messages...
487 temp = cupsArrayFirst(job->history);
488 cupsArrayRemove(job->history, temp);
497 else if (level <= LogLevel &&
498 (level != CUPSD_LOG_INFO || LogLevel >= CUPSD_LOG_DEBUG))
499 return (cupsdWriteErrorLog(level, log_line));
504 return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
505 "Unable to allocate memory for log line!"));
510 * 'cupsdLogMessage()' - Log a message to the error log file.
513 int /* O - 1 on success, 0 on error */
514 cupsdLogMessage(int level, /* I - Log level */
515 const char *message, /* I - printf-style message string */
516 ...) /* I - Additional args as needed */
518 va_list ap; /* Argument pointer */
519 int status; /* Formatting status */
523 * See if we want to log this message...
526 if ((TestConfigFile || !ErrorLog) && level <= CUPSD_LOG_WARN)
528 va_start(ap, message);
529 vfprintf(stderr, message, ap);
536 if (level > LogLevel || !ErrorLog)
540 * Format and write the log message...
545 va_start(ap, message);
546 status = format_log_line(message, ap);
552 return (cupsdWriteErrorLog(level, log_line));
554 return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
555 "Unable to allocate memory for log line!"));
560 * 'cupsdLogPage()' - Log a page to the page log file.
563 int /* O - 1 on success, 0 on error */
564 cupsdLogPage(cupsd_job_t *job, /* I - Job being printed */
565 const char *page) /* I - Page being printed */
567 int i; /* Looping var */
568 char buffer[2048], /* Buffer for page log */
569 *bufptr, /* Pointer into buffer */
570 name[256]; /* Attribute name */
571 const char *format, /* Pointer into PageLogFormat */
572 *nameend; /* End of attribute name */
573 ipp_attribute_t *attr; /* Current attribute */
574 char number[256]; /* Page number */
575 int copies; /* Number of copies */
579 * Format the line going into the page log...
587 sscanf(page, "%255s%d", number, &copies);
589 for (format = PageLogFormat, bufptr = buffer; *format; format ++)
597 case '%' : /* Literal % */
598 if (bufptr < (buffer + sizeof(buffer) - 1))
602 case 'p' : /* Printer name */
603 strlcpy(bufptr, job->printer->name,
604 sizeof(buffer) - (bufptr - buffer));
605 bufptr += strlen(bufptr);
608 case 'j' : /* Job ID */
609 snprintf(bufptr, sizeof(buffer) - (bufptr - buffer), "%d", job->id);
610 bufptr += strlen(bufptr);
613 case 'u' : /* Username */
614 strlcpy(bufptr, job->username ? job->username : "-",
615 sizeof(buffer) - (bufptr - buffer));
616 bufptr += strlen(bufptr);
619 case 'T' : /* Date and time */
620 strlcpy(bufptr, cupsdGetDateTime(NULL, LogTimeFormat),
621 sizeof(buffer) - (bufptr - buffer));
622 bufptr += strlen(bufptr);
625 case 'P' : /* Page number */
626 strlcpy(bufptr, number, sizeof(buffer) - (bufptr - buffer));
627 bufptr += strlen(bufptr);
630 case 'C' : /* Number of copies */
631 snprintf(bufptr, sizeof(buffer) - (bufptr - buffer), "%d", copies);
632 bufptr += strlen(bufptr);
635 case '{' : /* {attribute} */
636 if ((nameend = strchr(format, '}')) != NULL &&
637 (nameend - format - 2) < (sizeof(name) - 1))
640 * Pull the name from inside the brackets...
643 memcpy(name, format + 1, nameend - format - 1);
644 name[nameend - format - 1] = '\0';
648 if ((attr = ippFindAttribute(job->attrs, name,
649 IPP_TAG_ZERO)) != NULL)
652 * Add the attribute value...
656 i < attr->num_values &&
657 bufptr < (buffer + sizeof(buffer) - 1);
663 switch (attr->value_tag)
665 case IPP_TAG_INTEGER :
667 snprintf(bufptr, sizeof(buffer) - (bufptr - buffer),
668 "%d", attr->values[i].integer);
669 bufptr += strlen(bufptr);
672 case IPP_TAG_BOOLEAN :
673 snprintf(bufptr, sizeof(buffer) - (bufptr - buffer),
674 "%d", attr->values[i].boolean);
675 bufptr += strlen(bufptr);
678 case IPP_TAG_TEXTLANG :
679 case IPP_TAG_NAMELANG :
682 case IPP_TAG_KEYWORD :
684 case IPP_TAG_URISCHEME :
685 case IPP_TAG_CHARSET :
686 case IPP_TAG_LANGUAGE :
687 case IPP_TAG_MIMETYPE :
688 strlcpy(bufptr, attr->values[i].string.text,
689 sizeof(buffer) - (bufptr - buffer));
690 bufptr += strlen(bufptr);
694 strlcpy(bufptr, "???",
695 sizeof(buffer) - (bufptr - buffer));
696 bufptr += strlen(bufptr);
701 else if (bufptr < (buffer + sizeof(buffer) - 1))
707 if (bufptr < (buffer + sizeof(buffer) - 2))
715 else if (bufptr < (buffer + sizeof(buffer) - 1))
723 * See if we are logging pages via syslog...
726 if (!strcmp(PageLog, "syslog"))
728 syslog(LOG_INFO, "%s", buffer);
732 #endif /* HAVE_VSYSLOG */
735 * Not using syslog; check the log file...
738 if (!cupsdCheckLogFile(&PageFile, PageLog))
742 * Print a page log entry of the form:
744 * printer user job-id [DD/MON/YYYY:HH:MM:SS +TTTT] page num-copies \
748 cupsFilePrintf(PageFile, "%s\n", buffer);
749 cupsFileFlush(PageFile);
756 * 'cupsdLogRequest()' - Log an HTTP request in Common Log Format.
759 int /* O - 1 on success, 0 on error */
760 cupsdLogRequest(cupsd_client_t *con, /* I - Request to log */
761 http_status_t code) /* I - Response code */
763 char temp[2048]; /* Temporary string for URI */
764 static const char * const states[] = /* HTTP client states... */
784 * Filter requests as needed...
787 if (AccessLogLevel < CUPSD_ACCESSLOG_ALL)
790 * Eliminate simple GET, POST, and PUT requests...
793 if ((con->operation == HTTP_GET &&
794 strncmp(con->uri, "/admin/conf", 11) &&
795 strncmp(con->uri, "/admin/log", 10)) ||
796 (con->operation == HTTP_POST && !con->request &&
797 strncmp(con->uri, "/admin", 6)) ||
798 (con->operation != HTTP_GET && con->operation != HTTP_POST &&
799 con->operation != HTTP_PUT))
802 if (con->request && con->response &&
803 (con->response->request.status.status_code < IPP_REDIRECTION_OTHER_SITE ||
804 con->response->request.status.status_code == IPP_NOT_FOUND))
807 * Check successful requests...
810 ipp_op_t op = con->request->request.op.operation_id;
811 static cupsd_accesslog_t standard_ops[] =
813 CUPSD_ACCESSLOG_ALL, /* reserved */
814 CUPSD_ACCESSLOG_ALL, /* reserved */
815 CUPSD_ACCESSLOG_ACTIONS,/* Print-Job */
816 CUPSD_ACCESSLOG_ACTIONS,/* Print-URI */
817 CUPSD_ACCESSLOG_ACTIONS,/* Validate-Job */
818 CUPSD_ACCESSLOG_ACTIONS,/* Create-Job */
819 CUPSD_ACCESSLOG_ACTIONS,/* Send-Document */
820 CUPSD_ACCESSLOG_ACTIONS,/* Send-URI */
821 CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Job */
822 CUPSD_ACCESSLOG_ALL, /* Get-Job-Attributes */
823 CUPSD_ACCESSLOG_ALL, /* Get-Jobs */
824 CUPSD_ACCESSLOG_ALL, /* Get-Printer-Attributes */
825 CUPSD_ACCESSLOG_ACTIONS,/* Hold-Job */
826 CUPSD_ACCESSLOG_ACTIONS,/* Release-Job */
827 CUPSD_ACCESSLOG_ACTIONS,/* Restart-Job */
828 CUPSD_ACCESSLOG_ALL, /* reserved */
829 CUPSD_ACCESSLOG_CONFIG, /* Pause-Printer */
830 CUPSD_ACCESSLOG_CONFIG, /* Resume-Printer */
831 CUPSD_ACCESSLOG_CONFIG, /* Purge-Jobs */
832 CUPSD_ACCESSLOG_CONFIG, /* Set-Printer-Attributes */
833 CUPSD_ACCESSLOG_ACTIONS,/* Set-Job-Attributes */
834 CUPSD_ACCESSLOG_CONFIG, /* Get-Printer-Supported-Values */
835 CUPSD_ACCESSLOG_ACTIONS,/* Create-Printer-Subscription */
836 CUPSD_ACCESSLOG_ACTIONS,/* Create-Job-Subscription */
837 CUPSD_ACCESSLOG_ALL, /* Get-Subscription-Attributes */
838 CUPSD_ACCESSLOG_ALL, /* Get-Subscriptions */
839 CUPSD_ACCESSLOG_ACTIONS,/* Renew-Subscription */
840 CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Subscription */
841 CUPSD_ACCESSLOG_ALL, /* Get-Notifications */
842 CUPSD_ACCESSLOG_ACTIONS,/* Send-Notifications */
843 CUPSD_ACCESSLOG_ALL, /* reserved */
844 CUPSD_ACCESSLOG_ALL, /* reserved */
845 CUPSD_ACCESSLOG_ALL, /* reserved */
846 CUPSD_ACCESSLOG_ALL, /* Get-Print-Support-Files */
847 CUPSD_ACCESSLOG_CONFIG, /* Enable-Printer */
848 CUPSD_ACCESSLOG_CONFIG, /* Disable-Printer */
849 CUPSD_ACCESSLOG_CONFIG, /* Pause-Printer-After-Current-Job */
850 CUPSD_ACCESSLOG_ACTIONS,/* Hold-New-Jobs */
851 CUPSD_ACCESSLOG_ACTIONS,/* Release-Held-New-Jobs */
852 CUPSD_ACCESSLOG_CONFIG, /* Deactivate-Printer */
853 CUPSD_ACCESSLOG_CONFIG, /* Activate-Printer */
854 CUPSD_ACCESSLOG_CONFIG, /* Restart-Printer */
855 CUPSD_ACCESSLOG_CONFIG, /* Shutdown-Printer */
856 CUPSD_ACCESSLOG_CONFIG, /* Startup-Printer */
857 CUPSD_ACCESSLOG_ACTIONS,/* Reprocess-Job */
858 CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Current-Job */
859 CUPSD_ACCESSLOG_ACTIONS,/* Suspend-Current-Job */
860 CUPSD_ACCESSLOG_ACTIONS,/* Resume-Job */
861 CUPSD_ACCESSLOG_ACTIONS,/* Promote-Job */
862 CUPSD_ACCESSLOG_ACTIONS /* Schedule-Job-After */
864 static cupsd_accesslog_t cups_ops[] =
866 CUPSD_ACCESSLOG_ALL, /* CUPS-Get-Default */
867 CUPSD_ACCESSLOG_ALL, /* CUPS-Get-Printers */
868 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Add-Modify-Printer */
869 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Delete-Printer */
870 CUPSD_ACCESSLOG_ALL, /* CUPS-Get-Classes */
871 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Add-Modify-Class */
872 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Delete-Class */
873 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Accept-Jobs */
874 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Reject-Jobs */
875 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Set-Default */
876 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Get-Devices */
877 CUPSD_ACCESSLOG_CONFIG, /* CUPS-Get-PPDs */
878 CUPSD_ACCESSLOG_ACTIONS,/* CUPS-Move-Job */
879 CUPSD_ACCESSLOG_ACTIONS,/* CUPS-Authenticate-Job */
880 CUPSD_ACCESSLOG_ALL /* CUPS-Get-PPD */
884 if ((op <= IPP_SCHEDULE_JOB_AFTER && standard_ops[op] > AccessLogLevel) ||
885 (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD &&
886 cups_ops[op - CUPS_GET_DEFAULT] > AccessLogLevel))
893 * See if we are logging accesses via syslog...
896 if (!strcmp(AccessLog, "syslog"))
899 "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s\n",
900 con->http.hostname, con->username[0] != '\0' ? con->username : "-",
901 states[con->operation], _httpEncodeURI(temp, con->uri, sizeof(temp)),
902 con->http.version / 100, con->http.version % 100,
903 code, CUPS_LLCAST con->bytes,
905 ippOpString(con->request->request.op.operation_id) : "-",
907 ippErrorString(con->response->request.status.status_code) : "-");
911 #endif /* HAVE_VSYSLOG */
914 * Not using syslog; check the log file...
917 if (!cupsdCheckLogFile(&AccessFile, AccessLog))
921 * Write a log of the request in "common log format"...
924 cupsFilePrintf(AccessFile,
925 "%s - %s %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s\n",
927 con->username[0] != '\0' ? con->username : "-",
928 cupsdGetDateTime(&(con->start), LogTimeFormat),
929 states[con->operation],
930 _httpEncodeURI(temp, con->uri, sizeof(temp)),
931 con->http.version / 100, con->http.version % 100,
932 code, CUPS_LLCAST con->bytes,
934 ippOpString(con->request->request.op.operation_id) : "-",
936 ippErrorString(con->response->request.status.status_code) :
939 cupsFileFlush(AccessFile);
946 * 'cupsdWriteErrorLog()' - Write a line to the ErrorLog.
949 int /* O - 1 on success, 0 on failure */
950 cupsdWriteErrorLog(int level, /* I - Log level */
951 const char *message) /* I - Message string */
953 static const char levels[] = /* Log levels... */
967 static const int syslevels[] = /* SYSLOG levels... */
980 #endif /* HAVE_VSYSLOG */
985 * See if we are logging errors via syslog...
988 if (!strcmp(ErrorLog, "syslog"))
990 syslog(syslevels[level], "%s", message);
993 #endif /* HAVE_VSYSLOG */
996 * Not using syslog; check the log file...
999 if (!cupsdCheckLogFile(&ErrorFile, ErrorLog))
1003 * Write the log message...
1006 cupsFilePrintf(ErrorFile, "%c %s %s\n", levels[level],
1007 cupsdGetDateTime(NULL, LogTimeFormat), message);
1008 cupsFileFlush(ErrorFile);
1015 * 'format_log_line()' - Format a line for a log file.
1017 * This function resizes a global string buffer as needed. Each call returns
1018 * a pointer to this buffer, so the contents are only good until the next call
1019 * to format_log_line()...
1022 static int /* O - -1 for fatal, 0 for retry, 1 for success */
1023 format_log_line(const char *message, /* I - Printf-style format string */
1024 va_list ap) /* I - Argument list */
1026 int len; /* Length of formatted line */
1030 * Allocate the line buffer as needed...
1035 log_linesize = 8192;
1036 log_line = malloc(log_linesize);
1043 * Format the log message...
1046 len = vsnprintf(log_line, log_linesize, message, ap);
1049 * Resize the buffer as needed...
1052 if (len >= log_linesize && log_linesize < 65536)
1054 char *temp; /* Temporary string pointer */
1061 else if (len > 65536)
1064 temp = realloc(log_line, len);
1080 * End of "$Id: log.c 9949 2011-08-31 04:58:33Z mike $".