/*
* Configuration file definitions for the CUPS scheduler.
*
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
* Copyright © 2007-2018 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
...) _CUPS_FORMAT(3, 4);
extern int cupsdLogMessage(int level, const char *message, ...) _CUPS_FORMAT(2, 3);
extern int cupsdLogPage(cupsd_job_t *job, const char *page);
+extern int cupsdLogPrinter(cupsd_printer_t *p, int level, const char *message, ...) _CUPS_FORMAT(3, 4);
extern int cupsdLogRequest(cupsd_client_t *con, http_status_t code);
extern int cupsdReadConfiguration(void);
extern int cupsdWriteErrorLog(int level, const char *message);
/*
* Log file routines for the CUPS scheduler.
*
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
* Copyright © 2007-2018 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
* information.
*/
-/*
- * Include necessary headers...
- */
-
#include "cupsd.h"
#include <stdarg.h>
#ifdef HAVE_ASL_H
}
+/*
+ * 'cupsdLogPrinter()' - Log a printer message.
+ */
+
+int /* O - 1 on success, 0 on error */
+cupsdLogPrinter(
+ cupsd_printer_t *p, /* I - Printer */
+ int level, /* I - Log level */
+ const char *message, /* I - Printf-style message string */
+ ...) /* I - Additional arguments as needed */
+{
+ va_list ap, ap2; /* Argument pointers */
+ char pmsg[1024]; /* Format string for printer message */
+ int status; /* Formatting status */
+
+
+ /*
+ * See if we want to log this message...
+ */
+
+ if (TestConfigFile || !ErrorLog)
+ return (1);
+
+ if (level > LogLevel)
+ return (1);
+
+ /*
+ * Format and write the log message...
+ */
+
+ if (p)
+ snprintf(pmsg, sizeof(pmsg), "[Printer %s] %s", p->name, message);
+ else
+ cupsCopyString(pmsg, message, sizeof(pmsg));
+
+ va_start(ap, message);
+
+ do
+ {
+ va_copy(ap2, ap);
+ status = format_log_line(pmsg, ap2);
+ va_end(ap2);
+ }
+ while (status == 0);
+
+ va_end(ap);
+
+ if (status > 0)
+ {
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
+ if (!strcmp(ErrorLog, "syslog"))
+ {
+ static const char * const printer_states[] =
+ { /* printer-state strings */
+ "Idle",
+ "Processing",
+ "Stopped"
+ };
+
+ if (p)
+ sd_journal_send("MESSAGE=%s", log_line,
+ "PRIORITY=%i", log_levels[level],
+ PWG_Event"=PrinterStateChanged",
+ PWG_ServiceURI"=%s", p ? p->uri : "",
+ PWG_ServiceState"=%s", printer_states[p->state - IPP_PSTATE_IDLE],
+ NULL);
+ else
+ sd_journal_send("MESSAGE=%s", log_line,
+ "PRIORITY=%i", log_levels[level],
+ NULL);
+
+ return (1);
+ }
+ else
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
+
+ return (cupsdWriteErrorLog(level, log_line));
+ }
+ else
+ return (cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line."));
+}
+
+
/*
* 'cupsdLogRequest()' - Log an HTTP request in Common Log Format.
*/