4 * Log file routines for the CUPS scheduler.
6 * Copyright 2007-2012 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...
41 static _cups_mutex_t log_mutex
= _CUPS_MUTEX_INITIALIZER
;
42 /* Mutex for logging */
43 static int log_linesize
= 0; /* Size of line for output file */
44 static char *log_line
= NULL
; /* Line for output file */
47 static const int syslevels
[] = /* SYSLOG levels... */
60 #endif /* HAVE_VSYSLOG */
67 static int format_log_line(const char *message
, va_list ap
);
71 * 'cupsdCheckLogFile()' - Open/rotate a log file if it needs it.
74 int /* O - 1 if log file open */
75 cupsdCheckLogFile(cups_file_t
**lf
, /* IO - Log file */
76 const char *logname
) /* I - Log filename */
78 char backname
[1024], /* Backup log filename */
79 filename
[1024], /* Formatted log filename */
80 *ptr
; /* Pointer into filename */
81 const char *logptr
; /* Pointer into log filename */
85 * See if we have a log file to check...
88 if (!lf
|| !logname
|| !logname
[0])
92 * Format the filename as needed...
96 (strncmp(logname
, "/dev/", 5) && cupsFileTell(*lf
) > MaxLogSize
&&
100 * Handle format strings...
103 filename
[sizeof(filename
) - 1] = '\0';
105 if (logname
[0] != '/')
107 strlcpy(filename
, ServerRoot
, sizeof(filename
));
108 strlcat(filename
, "/", sizeof(filename
));
113 for (logptr
= logname
, ptr
= filename
+ strlen(filename
);
114 *logptr
&& ptr
< (filename
+ sizeof(filename
) - 1);
126 * Insert the server name...
129 strlcpy(ptr
, ServerName
, sizeof(filename
) - (ptr
- filename
));
135 * Otherwise just insert the character...
148 * See if the log file is open...
154 * Nope, open the log file...
157 if ((*lf
= cupsFileOpen(filename
, "a")) == NULL
)
160 * If the file is in CUPS_LOGDIR then try to create a missing directory...
163 if (!strncmp(filename
, CUPS_LOGDIR
, strlen(CUPS_LOGDIR
)))
166 * Try updating the permissions of the containing log directory, using
167 * the log file permissions as a basis...
170 int log_dir_perm
= 0300 | LogFilePerm
;
171 /* LogFilePerm + owner write/search */
172 if (log_dir_perm
& 0040)
173 log_dir_perm
|= 0010; /* Add group search */
174 if (log_dir_perm
& 0004)
175 log_dir_perm
|= 0001; /* Add other search */
177 cupsdCheckPermissions(CUPS_LOGDIR
, NULL
, log_dir_perm
, RunUser
, Group
,
180 *lf
= cupsFileOpen(filename
, "a");
185 syslog(LOG_ERR
, "Unable to open log file \"%s\" - %s", filename
,
188 if (FatalErrors
& CUPSD_FATAL_LOG
)
189 cupsdEndProcess(getpid(), 0);
195 if (strncmp(filename
, "/dev/", 5))
198 * Change ownership and permissions of non-device logs...
201 fchown(cupsFileNumber(*lf
), RunUser
, Group
);
202 fchmod(cupsFileNumber(*lf
), LogFilePerm
);
207 * Do we need to rotate the log?
210 if (strncmp(logname
, "/dev/", 5) && cupsFileTell(*lf
) > MaxLogSize
&&
219 strlcpy(backname
, filename
, sizeof(backname
));
220 strlcat(backname
, ".O", sizeof(backname
));
223 rename(filename
, backname
);
225 if ((*lf
= cupsFileOpen(filename
, "a")) == NULL
)
227 syslog(LOG_ERR
, "Unable to open log file \"%s\" - %s", filename
,
230 if (FatalErrors
& CUPSD_FATAL_LOG
)
231 cupsdEndProcess(getpid(), 0);
237 * Change ownership and permissions of non-device logs...
240 fchown(cupsFileNumber(*lf
), RunUser
, Group
);
241 fchmod(cupsFileNumber(*lf
), LogFilePerm
);
249 * 'cupsdGetDateTime()' - Returns a pointer to a date/time string.
252 char * /* O - Date/time string */
253 cupsdGetDateTime(struct timeval
*t
, /* I - Time value or NULL for current */
254 cupsd_time_t format
) /* I - Format to use */
256 struct timeval curtime
; /* Current time value */
257 struct tm
*date
; /* Date/time value */
258 static struct timeval last_time
= { 0, 0 };
259 /* Last time we formatted */
260 static char s
[1024]; /* Date/time string */
261 static const char * const months
[12] =/* Months */
279 * Make sure we have a valid time...
284 gettimeofday(&curtime
, NULL
);
288 if (t
->tv_sec
!= last_time
.tv_sec
||
289 (LogTimeFormat
== CUPSD_TIME_USECS
&& t
->tv_usec
!= last_time
.tv_usec
))
294 * Get the date and time from the UNIX time value, and then format it
295 * into a string. Note that we *can't* use the strftime() function since
296 * it is localized and will seriously confuse automatic programs if the
297 * month names are in the wrong language!
299 * Also, we use the "timezone" variable that contains the current timezone
300 * offset from GMT in seconds so that we are reporting local time in the
301 * log files. If you want GMT, set the TZ environment variable accordingly
302 * before starting the scheduler.
304 * (*BSD and Darwin store the timezone offset in the tm structure)
307 date
= localtime(&(t
->tv_sec
));
309 if (format
== CUPSD_TIME_STANDARD
)
310 snprintf(s
, sizeof(s
), "[%02d/%s/%04d:%02d:%02d:%02d %+03ld%02ld]",
311 date
->tm_mday
, months
[date
->tm_mon
], 1900 + date
->tm_year
,
312 date
->tm_hour
, date
->tm_min
, date
->tm_sec
,
313 #ifdef HAVE_TM_GMTOFF
314 date
->tm_gmtoff
/ 3600, (date
->tm_gmtoff
/ 60) % 60);
316 timezone
/ 3600, (timezone
/ 60) % 60);
317 #endif /* HAVE_TM_GMTOFF */
319 snprintf(s
, sizeof(s
), "[%02d/%s/%04d:%02d:%02d:%02d.%06d %+03ld%02ld]",
320 date
->tm_mday
, months
[date
->tm_mon
], 1900 + date
->tm_year
,
321 date
->tm_hour
, date
->tm_min
, date
->tm_sec
, (int)t
->tv_usec
,
322 #ifdef HAVE_TM_GMTOFF
323 date
->tm_gmtoff
/ 3600, (date
->tm_gmtoff
/ 60) % 60);
325 timezone
/ 3600, (timezone
/ 60) % 60);
326 #endif /* HAVE_TM_GMTOFF */
334 * 'cupsdLogFCMessage()' - Log a file checking message.
339 void *context
, /* I - Printer (if any) */
340 _cups_fc_result_t result
, /* I - Check result */
341 const char *message
) /* I - Message to log */
343 cupsd_printer_t
*p
= (cupsd_printer_t
*)context
;
345 cupsd_loglevel_t level
; /* Log level */
348 if (result
== _CUPS_FILE_CHECK_OK
)
349 level
= CUPSD_LOG_DEBUG2
;
351 level
= CUPSD_LOG_ERROR
;
355 cupsdLogMessage(level
, "%s: %s", p
->name
, message
);
357 if (result
== _CUPS_FILE_CHECK_MISSING
||
358 result
== _CUPS_FILE_CHECK_WRONG_TYPE
)
360 strlcpy(p
->state_message
, message
, sizeof(p
->state_message
));
362 if (cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning"))
363 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, p
, NULL
, "%s", message
);
365 else if (result
== _CUPS_FILE_CHECK_PERMISSIONS
||
366 result
== _CUPS_FILE_CHECK_RELATIVE_PATH
)
368 strlcpy(p
->state_message
, message
, sizeof(p
->state_message
));
370 if (cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning"))
371 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, p
, NULL
, "%s", message
);
375 cupsdLogMessage(level
, "%s", message
);
381 * 'cupsdLogGSSMessage()' - Log a GSSAPI error...
384 int /* O - 1 on success, 0 on error */
386 int level
, /* I - Log level */
387 int major_status
, /* I - Major GSSAPI status */
388 int minor_status
, /* I - Minor GSSAPI status */
389 const char *message
, /* I - printf-style message string */
390 ...) /* I - Additional args as needed */
392 OM_uint32 err_major_status
, /* Major status code for display */
393 err_minor_status
; /* Minor status code for display */
394 OM_uint32 msg_ctx
; /* Message context */
395 gss_buffer_desc major_status_string
= GSS_C_EMPTY_BUFFER
,
396 /* Major status message */
397 minor_status_string
= GSS_C_EMPTY_BUFFER
;
398 /* Minor status message */
399 int ret
; /* Return value */
400 char buffer
[8192]; /* Buffer for vsnprintf */
403 if (strchr(message
, '%'))
406 * Format the message string...
409 va_list ap
; /* Pointer to arguments */
411 va_start(ap
, message
);
412 vsnprintf(buffer
, sizeof(buffer
), message
, ap
);
419 err_major_status
= gss_display_status(&err_minor_status
,
424 &major_status_string
);
426 if (!GSS_ERROR(err_major_status
))
427 gss_display_status(&err_minor_status
, minor_status
, GSS_C_MECH_CODE
,
428 GSS_C_NULL_OID
, &msg_ctx
, &minor_status_string
);
430 ret
= cupsdLogMessage(level
, "%s: %s, %s", message
,
431 (char *)major_status_string
.value
,
432 (char *)minor_status_string
.value
);
433 gss_release_buffer(&err_minor_status
, &major_status_string
);
434 gss_release_buffer(&err_minor_status
, &minor_status_string
);
438 #endif /* HAVE_GSSAPI */
442 * 'cupsdLogJob()' - Log a job message.
445 int /* O - 1 on success, 0 on error */
446 cupsdLogJob(cupsd_job_t
*job
, /* I - Job */
447 int level
, /* I - Log level */
448 const char *message
, /* I - Printf-style message string */
449 ...) /* I - Additional arguments as needed */
451 va_list ap
, ap2
; /* Argument pointers */
452 char jobmsg
[1024]; /* Format string for job message */
453 int status
; /* Formatting status */
457 * See if we want to log this message...
460 if (TestConfigFile
|| !ErrorLog
)
463 if ((level
> LogLevel
||
464 (level
== CUPSD_LOG_INFO
&& LogLevel
< CUPSD_LOG_DEBUG
)) &&
465 LogDebugHistory
<= 0)
469 * Format and write the log message...
473 snprintf(jobmsg
, sizeof(jobmsg
), "[Job %d] %s", job
->id
, message
);
475 strlcpy(jobmsg
, message
, sizeof(jobmsg
));
477 va_start(ap
, message
);
482 status
= format_log_line(jobmsg
, ap2
);
493 (level
== CUPSD_LOG_INFO
&& LogLevel
< CUPSD_LOG_DEBUG
)) &&
497 * Add message to the job history...
500 cupsd_joblog_t
*temp
; /* Copy of log message */
503 if ((temp
= malloc(sizeof(cupsd_joblog_t
) + strlen(log_line
))) != NULL
)
505 temp
->time
= time(NULL
);
506 strlcpy(temp
->message
, log_line
, sizeof(temp
->message
));
510 job
->history
= cupsArrayNew(NULL
, NULL
);
512 if (job
->history
&& temp
)
514 cupsArrayAdd(job
->history
, temp
);
516 if (cupsArrayCount(job
->history
) > LogDebugHistory
)
519 * Remove excess messages...
522 temp
= cupsArrayFirst(job
->history
);
523 cupsArrayRemove(job
->history
, temp
);
532 else if (level
<= LogLevel
&&
533 (level
!= CUPSD_LOG_INFO
|| LogLevel
>= CUPSD_LOG_DEBUG
))
534 return (cupsdWriteErrorLog(level
, log_line
));
539 return (cupsdWriteErrorLog(CUPSD_LOG_ERROR
,
540 "Unable to allocate memory for log line!"));
545 * 'cupsdLogMessage()' - Log a message to the error log file.
548 int /* O - 1 on success, 0 on error */
549 cupsdLogMessage(int level
, /* I - Log level */
550 const char *message
, /* I - printf-style message string */
551 ...) /* I - Additional args as needed */
553 va_list ap
, ap2
; /* Argument pointers */
554 int status
; /* Formatting status */
558 * See if we want to log this message...
561 if ((TestConfigFile
|| !ErrorLog
) && level
<= CUPSD_LOG_WARN
)
563 va_start(ap
, message
);
565 vsyslog(LOG_LPR
| syslevels
[level
], message
, ap
);
567 vfprintf(stderr
, message
, ap
);
569 #endif /* HAVE_VSYSLOG */
575 if (level
> LogLevel
|| !ErrorLog
)
579 * Format and write the log message...
582 va_start(ap
, message
);
587 status
= format_log_line(message
, ap2
);
595 return (cupsdWriteErrorLog(level
, log_line
));
597 return (cupsdWriteErrorLog(CUPSD_LOG_ERROR
,
598 "Unable to allocate memory for log line!"));
603 * 'cupsdLogPage()' - Log a page to the page log file.
606 int /* O - 1 on success, 0 on error */
607 cupsdLogPage(cupsd_job_t
*job
, /* I - Job being printed */
608 const char *page
) /* I - Page being printed */
610 int i
; /* Looping var */
611 char buffer
[2048], /* Buffer for page log */
612 *bufptr
, /* Pointer into buffer */
613 name
[256]; /* Attribute name */
614 const char *format
, /* Pointer into PageLogFormat */
615 *nameend
; /* End of attribute name */
616 ipp_attribute_t
*attr
; /* Current attribute */
617 char number
[256]; /* Page number */
618 int copies
; /* Number of copies */
622 * Format the line going into the page log...
628 strlcpy(number
, "1", sizeof(number
));
630 sscanf(page
, "%255s%d", number
, &copies
);
632 for (format
= PageLogFormat
, bufptr
= buffer
; *format
; format
++)
640 case '%' : /* Literal % */
641 if (bufptr
< (buffer
+ sizeof(buffer
) - 1))
645 case 'p' : /* Printer name */
646 strlcpy(bufptr
, job
->printer
->name
,
647 sizeof(buffer
) - (bufptr
- buffer
));
648 bufptr
+= strlen(bufptr
);
651 case 'j' : /* Job ID */
652 snprintf(bufptr
, sizeof(buffer
) - (bufptr
- buffer
), "%d", job
->id
);
653 bufptr
+= strlen(bufptr
);
656 case 'u' : /* Username */
657 strlcpy(bufptr
, job
->username
? job
->username
: "-",
658 sizeof(buffer
) - (bufptr
- buffer
));
659 bufptr
+= strlen(bufptr
);
662 case 'T' : /* Date and time */
663 strlcpy(bufptr
, cupsdGetDateTime(NULL
, LogTimeFormat
),
664 sizeof(buffer
) - (bufptr
- buffer
));
665 bufptr
+= strlen(bufptr
);
668 case 'P' : /* Page number */
669 strlcpy(bufptr
, number
, sizeof(buffer
) - (bufptr
- buffer
));
670 bufptr
+= strlen(bufptr
);
673 case 'C' : /* Number of copies */
674 snprintf(bufptr
, sizeof(buffer
) - (bufptr
- buffer
), "%d", copies
);
675 bufptr
+= strlen(bufptr
);
678 case '{' : /* {attribute} */
679 if ((nameend
= strchr(format
, '}')) != NULL
&&
680 (nameend
- format
- 2) < (sizeof(name
) - 1))
683 * Pull the name from inside the brackets...
686 memcpy(name
, format
+ 1, nameend
- format
- 1);
687 name
[nameend
- format
- 1] = '\0';
691 if ((attr
= ippFindAttribute(job
->attrs
, name
,
692 IPP_TAG_ZERO
)) != NULL
)
695 * Add the attribute value...
699 i
< attr
->num_values
&&
700 bufptr
< (buffer
+ sizeof(buffer
) - 1);
706 switch (attr
->value_tag
)
708 case IPP_TAG_INTEGER
:
710 snprintf(bufptr
, sizeof(buffer
) - (bufptr
- buffer
),
711 "%d", attr
->values
[i
].integer
);
712 bufptr
+= strlen(bufptr
);
715 case IPP_TAG_BOOLEAN
:
716 snprintf(bufptr
, sizeof(buffer
) - (bufptr
- buffer
),
717 "%d", attr
->values
[i
].boolean
);
718 bufptr
+= strlen(bufptr
);
721 case IPP_TAG_TEXTLANG
:
722 case IPP_TAG_NAMELANG
:
725 case IPP_TAG_KEYWORD
:
727 case IPP_TAG_URISCHEME
:
728 case IPP_TAG_CHARSET
:
729 case IPP_TAG_LANGUAGE
:
730 case IPP_TAG_MIMETYPE
:
731 strlcpy(bufptr
, attr
->values
[i
].string
.text
,
732 sizeof(buffer
) - (bufptr
- buffer
));
733 bufptr
+= strlen(bufptr
);
737 strlcpy(bufptr
, "???",
738 sizeof(buffer
) - (bufptr
- buffer
));
739 bufptr
+= strlen(bufptr
);
744 else if (bufptr
< (buffer
+ sizeof(buffer
) - 1))
750 if (bufptr
< (buffer
+ sizeof(buffer
) - 2))
758 else if (bufptr
< (buffer
+ sizeof(buffer
) - 1))
766 * See if we are logging pages via syslog...
769 if (!strcmp(PageLog
, "syslog"))
771 syslog(LOG_INFO
, "%s", buffer
);
775 #endif /* HAVE_VSYSLOG */
778 * Not using syslog; check the log file...
781 if (!cupsdCheckLogFile(&PageFile
, PageLog
))
785 * Print a page log entry of the form:
787 * printer user job-id [DD/MON/YYYY:HH:MM:SS +TTTT] page num-copies \
791 cupsFilePrintf(PageFile
, "%s\n", buffer
);
792 cupsFileFlush(PageFile
);
799 * 'cupsdLogRequest()' - Log an HTTP request in Common Log Format.
802 int /* O - 1 on success, 0 on error */
803 cupsdLogRequest(cupsd_client_t
*con
, /* I - Request to log */
804 http_status_t code
) /* I - Response code */
806 char temp
[2048]; /* Temporary string for URI */
807 static const char * const states
[] = /* HTTP client states... */
827 * Filter requests as needed...
830 if (AccessLogLevel
< CUPSD_ACCESSLOG_ALL
)
833 * Eliminate simple GET, POST, and PUT requests...
836 if ((con
->operation
== HTTP_GET
&&
837 strncmp(con
->uri
, "/admin/conf", 11) &&
838 strncmp(con
->uri
, "/admin/log", 10)) ||
839 (con
->operation
== HTTP_POST
&& !con
->request
&&
840 strncmp(con
->uri
, "/admin", 6)) ||
841 (con
->operation
!= HTTP_GET
&& con
->operation
!= HTTP_POST
&&
842 con
->operation
!= HTTP_PUT
))
845 if (con
->request
&& con
->response
&&
846 (con
->response
->request
.status
.status_code
< IPP_REDIRECTION_OTHER_SITE
||
847 con
->response
->request
.status
.status_code
== IPP_NOT_FOUND
))
850 * Check successful requests...
853 ipp_op_t op
= con
->request
->request
.op
.operation_id
;
854 static cupsd_accesslog_t standard_ops
[] =
856 CUPSD_ACCESSLOG_ALL
, /* reserved */
857 CUPSD_ACCESSLOG_ALL
, /* reserved */
858 CUPSD_ACCESSLOG_ACTIONS
,/* Print-Job */
859 CUPSD_ACCESSLOG_ACTIONS
,/* Print-URI */
860 CUPSD_ACCESSLOG_ACTIONS
,/* Validate-Job */
861 CUPSD_ACCESSLOG_ACTIONS
,/* Create-Job */
862 CUPSD_ACCESSLOG_ACTIONS
,/* Send-Document */
863 CUPSD_ACCESSLOG_ACTIONS
,/* Send-URI */
864 CUPSD_ACCESSLOG_ACTIONS
,/* Cancel-Job */
865 CUPSD_ACCESSLOG_ALL
, /* Get-Job-Attributes */
866 CUPSD_ACCESSLOG_ALL
, /* Get-Jobs */
867 CUPSD_ACCESSLOG_ALL
, /* Get-Printer-Attributes */
868 CUPSD_ACCESSLOG_ACTIONS
,/* Hold-Job */
869 CUPSD_ACCESSLOG_ACTIONS
,/* Release-Job */
870 CUPSD_ACCESSLOG_ACTIONS
,/* Restart-Job */
871 CUPSD_ACCESSLOG_ALL
, /* reserved */
872 CUPSD_ACCESSLOG_CONFIG
, /* Pause-Printer */
873 CUPSD_ACCESSLOG_CONFIG
, /* Resume-Printer */
874 CUPSD_ACCESSLOG_CONFIG
, /* Purge-Jobs */
875 CUPSD_ACCESSLOG_CONFIG
, /* Set-Printer-Attributes */
876 CUPSD_ACCESSLOG_ACTIONS
,/* Set-Job-Attributes */
877 CUPSD_ACCESSLOG_CONFIG
, /* Get-Printer-Supported-Values */
878 CUPSD_ACCESSLOG_ACTIONS
,/* Create-Printer-Subscription */
879 CUPSD_ACCESSLOG_ACTIONS
,/* Create-Job-Subscription */
880 CUPSD_ACCESSLOG_ALL
, /* Get-Subscription-Attributes */
881 CUPSD_ACCESSLOG_ALL
, /* Get-Subscriptions */
882 CUPSD_ACCESSLOG_ACTIONS
,/* Renew-Subscription */
883 CUPSD_ACCESSLOG_ACTIONS
,/* Cancel-Subscription */
884 CUPSD_ACCESSLOG_ALL
, /* Get-Notifications */
885 CUPSD_ACCESSLOG_ACTIONS
,/* Send-Notifications */
886 CUPSD_ACCESSLOG_ALL
, /* reserved */
887 CUPSD_ACCESSLOG_ALL
, /* reserved */
888 CUPSD_ACCESSLOG_ALL
, /* reserved */
889 CUPSD_ACCESSLOG_ALL
, /* Get-Print-Support-Files */
890 CUPSD_ACCESSLOG_CONFIG
, /* Enable-Printer */
891 CUPSD_ACCESSLOG_CONFIG
, /* Disable-Printer */
892 CUPSD_ACCESSLOG_CONFIG
, /* Pause-Printer-After-Current-Job */
893 CUPSD_ACCESSLOG_ACTIONS
,/* Hold-New-Jobs */
894 CUPSD_ACCESSLOG_ACTIONS
,/* Release-Held-New-Jobs */
895 CUPSD_ACCESSLOG_CONFIG
, /* Deactivate-Printer */
896 CUPSD_ACCESSLOG_CONFIG
, /* Activate-Printer */
897 CUPSD_ACCESSLOG_CONFIG
, /* Restart-Printer */
898 CUPSD_ACCESSLOG_CONFIG
, /* Shutdown-Printer */
899 CUPSD_ACCESSLOG_CONFIG
, /* Startup-Printer */
900 CUPSD_ACCESSLOG_ACTIONS
,/* Reprocess-Job */
901 CUPSD_ACCESSLOG_ACTIONS
,/* Cancel-Current-Job */
902 CUPSD_ACCESSLOG_ACTIONS
,/* Suspend-Current-Job */
903 CUPSD_ACCESSLOG_ACTIONS
,/* Resume-Job */
904 CUPSD_ACCESSLOG_ACTIONS
,/* Promote-Job */
905 CUPSD_ACCESSLOG_ACTIONS
/* Schedule-Job-After */
907 static cupsd_accesslog_t cups_ops
[] =
909 CUPSD_ACCESSLOG_ALL
, /* CUPS-Get-Default */
910 CUPSD_ACCESSLOG_ALL
, /* CUPS-Get-Printers */
911 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Add-Modify-Printer */
912 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Delete-Printer */
913 CUPSD_ACCESSLOG_ALL
, /* CUPS-Get-Classes */
914 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Add-Modify-Class */
915 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Delete-Class */
916 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Accept-Jobs */
917 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Reject-Jobs */
918 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Set-Default */
919 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Get-Devices */
920 CUPSD_ACCESSLOG_CONFIG
, /* CUPS-Get-PPDs */
921 CUPSD_ACCESSLOG_ACTIONS
,/* CUPS-Move-Job */
922 CUPSD_ACCESSLOG_ACTIONS
,/* CUPS-Authenticate-Job */
923 CUPSD_ACCESSLOG_ALL
/* CUPS-Get-PPD */
927 if ((op
<= IPP_SCHEDULE_JOB_AFTER
&& standard_ops
[op
] > AccessLogLevel
) ||
928 (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_GET_PPD
&&
929 cups_ops
[op
- CUPS_GET_DEFAULT
] > AccessLogLevel
))
936 * See if we are logging accesses via syslog...
939 if (!strcmp(AccessLog
, "syslog"))
942 "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT
" %s %s\n",
943 con
->http
.hostname
, con
->username
[0] != '\0' ? con
->username
: "-",
944 states
[con
->operation
], _httpEncodeURI(temp
, con
->uri
, sizeof(temp
)),
945 con
->http
.version
/ 100, con
->http
.version
% 100,
946 code
, CUPS_LLCAST con
->bytes
,
948 ippOpString(con
->request
->request
.op
.operation_id
) : "-",
950 ippErrorString(con
->response
->request
.status
.status_code
) : "-");
954 #endif /* HAVE_VSYSLOG */
957 * Not using syslog; check the log file...
960 if (!cupsdCheckLogFile(&AccessFile
, AccessLog
))
964 * Write a log of the request in "common log format"...
967 cupsFilePrintf(AccessFile
,
968 "%s - %s %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT
" %s %s\n",
970 con
->username
[0] != '\0' ? con
->username
: "-",
971 cupsdGetDateTime(&(con
->start
), LogTimeFormat
),
972 states
[con
->operation
],
973 _httpEncodeURI(temp
, con
->uri
, sizeof(temp
)),
974 con
->http
.version
/ 100, con
->http
.version
% 100,
975 code
, CUPS_LLCAST con
->bytes
,
977 ippOpString(con
->request
->request
.op
.operation_id
) : "-",
979 ippErrorString(con
->response
->request
.status
.status_code
) :
982 cupsFileFlush(AccessFile
);
989 * 'cupsdWriteErrorLog()' - Write a line to the ErrorLog.
992 int /* O - 1 on success, 0 on failure */
993 cupsdWriteErrorLog(int level
, /* I - Log level */
994 const char *message
) /* I - Message string */
996 int ret
= 1; /* Return value */
997 static const char levels
[] = /* Log levels... */
1014 * See if we are logging errors via syslog...
1017 if (!strcmp(ErrorLog
, "syslog"))
1019 syslog(syslevels
[level
], "%s", message
);
1022 #endif /* HAVE_VSYSLOG */
1025 * Not using syslog; check the log file...
1028 _cupsMutexLock(&log_mutex
);
1030 if (!cupsdCheckLogFile(&ErrorFile
, ErrorLog
))
1037 * Write the log message...
1040 cupsFilePrintf(ErrorFile
, "%c %s %s\n", levels
[level
],
1041 cupsdGetDateTime(NULL
, LogTimeFormat
), message
);
1042 cupsFileFlush(ErrorFile
);
1045 _cupsMutexUnlock(&log_mutex
);
1052 * 'format_log_line()' - Format a line for a log file.
1054 * This function resizes a global string buffer as needed. Each call returns
1055 * a pointer to this buffer, so the contents are only good until the next call
1056 * to format_log_line()...
1059 static int /* O - -1 for fatal, 0 for retry, 1 for success */
1060 format_log_line(const char *message
, /* I - Printf-style format string */
1061 va_list ap
) /* I - Argument list */
1063 int len
; /* Length of formatted line */
1067 * Allocate the line buffer as needed...
1072 log_linesize
= 8192;
1073 log_line
= malloc(log_linesize
);
1080 * Format the log message...
1083 len
= vsnprintf(log_line
, log_linesize
, message
, ap
);
1086 * Resize the buffer as needed...
1089 if (len
>= log_linesize
&& log_linesize
< 65536)
1091 char *temp
; /* Temporary string pointer */
1098 else if (len
> 65536)
1101 temp
= realloc(log_line
, len
);