php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52052
Patch fpm-syslog.v5.patch revision 2011-01-28 14:48 UTC by ef-lists at email dot de
Patch fpm-syslog.v4.patch revision 2010-07-07 10:14 UTC by ef-lists at email dot de
Patch fpm-syslog.v3.patch revision 2010-06-13 09:03 UTC by fat@php.net
Patch fpm-syslog.v2.patch revision 2010-06-13 08:36 UTC by fat@php.net
Patch fpm-syslog.v1.patch revision 2010-06-12 16:47 UTC by fat@php.net

Patch fpm-syslog.v4.patch for FPM related Bug #52052

Patch version 2010-07-07 10:14 UTC

Return to Bug #52052 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: ef-lists@email.de

diff -Naur ../1/sapi/fpm/fpm/fpm_conf.c sapi/fpm/fpm/fpm_conf.c
--- ../1/sapi/fpm/fpm/fpm_conf.c	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/fpm_conf.c	2010-07-07 09:35:10.000000000 +0200
@@ -31,6 +31,7 @@
 #include "zend_ini_scanner.h"
 #include "zend_globals.h"
 #include "zend_stream.h"
+#include "php_syslog.h"
 
 #include "fpm.h"
 #include "fpm_conf.h"
@@ -51,8 +52,25 @@
 static char *fpm_conf_set_log_level(zval *value, void **config, intptr_t offset);
 static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset);
 static char *fpm_conf_set_pm(zval *value, void **config, intptr_t offset);
+#ifdef HAVE_SYSLOG_H
+static char *fpm_conf_set_syslog_facility(zval *value, void **config, intptr_t offset);
+#endif
+
+struct fpm_global_config_s fpm_global_config = 
+	{
+		0, /* emergency_restart_threshold */
+		0, /* emergency_restart_interval */
+		0, /* process_control_timeout */
+		1, /* daemonize */
+		NULL, /* pid_file */
+		NULL, /* error_log */
+		ZLOG_NOTICE, /* log_level */
+#ifdef HAVE_SYSLOG_H
+		NULL, /* syslog_ident */
+		-1, /* syslog_facility */
+#endif
+};
 
-struct fpm_global_config_s fpm_global_config = { 0, 0, 0, 1, NULL, NULL};
 static struct fpm_worker_pool_s *current_wp = NULL;
 static int ini_recursion = 0;
 static char *ini_filename = NULL;
@@ -66,7 +84,11 @@
 	{ "daemonize",										&fpm_conf_set_boolean,	offsetof(struct fpm_global_config_s, daemonize) },
 	{ "pid",													&fpm_conf_set_string,		offsetof(struct fpm_global_config_s, pid_file) },
 	{ "error_log",										&fpm_conf_set_string,		offsetof(struct fpm_global_config_s, error_log) },
-	{ "log_level",										&fpm_conf_set_log_level,	0 },
+#ifdef HAVE_SYSLOG_H
+	{ "syslog_ident",									&fpm_conf_set_string,		offsetof(struct fpm_global_config_s, syslog_ident) },
+	{ "syslog_facility",							&fpm_conf_set_syslog_facility,	offsetof(struct fpm_global_config_s, syslog_facility) },
+#endif
+	{ "log_level",										&fpm_conf_set_log_level,	offsetof(struct fpm_global_config_s, log_level) },
 	{ 0, 0, 0 }
 };
 
@@ -78,6 +100,9 @@
 	{ "request_terminate_timeout", &fpm_conf_set_time, offsetof(struct fpm_worker_pool_config_s, request_terminate_timeout) },
 	{ "request_slowlog_timeout", &fpm_conf_set_time, offsetof(struct fpm_worker_pool_config_s, request_slowlog_timeout) },
 	{ "slowlog", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, slowlog) },
+#ifdef HAVE_SYSLOG_H
+	{ "slowlog_syslog_level", &fpm_conf_set_log_level, offsetof(struct fpm_worker_pool_config_s, slowlog_syslog_level) },
+#endif
 	{ "rlimit_files", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, rlimit_files) },
 	{ "rlimit_core", &fpm_conf_set_rlimit_core, offsetof(struct fpm_worker_pool_config_s, rlimit_core) },
 	{ "catch_workers_output", &fpm_conf_set_boolean, offsetof(struct fpm_worker_pool_config_s, catch_workers_output) },
@@ -203,25 +228,178 @@
 static char *fpm_conf_set_log_level(zval *value, void **config, intptr_t offset) /* {{{ */
 {
 	char *val = Z_STRVAL_P(value);
+	int log_level;
 
 	if (!strcmp(val, "debug")) {
-		fpm_globals.log_level = ZLOG_DEBUG;
+		log_level = ZLOG_DEBUG;
 	} else if (!strcasecmp(val, "notice")) {
-		fpm_globals.log_level = ZLOG_NOTICE;
+		log_level = ZLOG_NOTICE;
 	} else if (!strcasecmp(val, "warning") || !strcasecmp(val, "warn")) {
-		fpm_globals.log_level = ZLOG_WARNING;
+		log_level = ZLOG_WARNING;
 	} else if (!strcasecmp(val, "error")) {
-		fpm_globals.log_level = ZLOG_ERROR;
+		log_level = ZLOG_ERROR;
 	} else if (!strcasecmp(val, "alert")) {
-		fpm_globals.log_level = ZLOG_ALERT;
+		log_level = ZLOG_ALERT;
 	} else {
 		return "invalid value for 'log_level'";
 	}
 
+	* (int *) ((char *) *config + offset) = log_level;
 	return NULL;
 }
 /* }}} */
 
+#ifdef HAVE_SYSLOG_H
+static char *fpm_conf_set_syslog_facility(zval *value, void **config, intptr_t offset) /* {{{ */
+{
+	char *val = Z_STRVAL_P(value);
+	int *conf = (int *) ((char *) *config + offset);
+
+#ifdef LOG_AUTH
+	if (!strcasecmp(val, "AUTH")) {
+		*conf = LOG_AUTH;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_AUTHPRIV
+	if (!strcasecmp(val, "AUTHPRIV")) {
+		*conf = LOG_AUTHPRIV;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_CRON
+	if (!strcasecmp(val, "CRON")) {
+		*conf = LOG_CRON;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_DAEMON
+	if (!strcasecmp(val, "DAEMON")) {
+		*conf = LOG_DAEMON;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_FTP
+	if (!strcasecmp(val, "FTP")) {
+		*conf = LOG_FTP;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_KERN
+	if (!strcasecmp(val, "KERN")) {
+		*conf = LOG_KERN;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LPR
+	if (!strcasecmp(val, "LPR")) {
+		*conf = LOG_LPR;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_MAIL
+	if (!strcasecmp(val, "MAIL")) {
+		*conf = LOG_MAIL;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_NEWS
+	if (!strcasecmp(val, "NEWS")) {
+		*conf = LOG_NEWS;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_SYSLOG
+	if (!strcasecmp(val, "SYSLOG")) {
+		*conf = LOG_SYSLOG;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_USER
+	if (!strcasecmp(val, "USER")) {
+		*conf = LOG_USER;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_UUCP
+	if (!strcmp(val, "UUCP")) {
+		*conf = LOG_UUCP;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL0
+	if (!strcmp(val, "LOCAL0")) {
+		*conf = LOG_LOCAL0;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL1
+	if (!strcmp(val, "LOCAL1")) {
+		*conf = LOG_LOCAL1;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL2
+	if (!strcmp(val, "LOCAL2")) {
+		*conf = LOG_LOCAL2;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL3
+	if (!strcmp(val, "LOCAL3")) {
+		*conf = LOG_LOCAL3;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL4
+	if (!strcmp(val, "LOCAL4")) {
+		*conf = LOG_LOCAL4;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL5
+	if (!strcmp(val, "LOCAL5")) {
+		*conf = LOG_LOCAL5;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL6
+	if (!strcmp(val, "LOCAL6")) {
+		*conf = LOG_LOCAL6;
+		return NULL;
+	}
+#endif
+
+#ifdef LOG_LOCAL7
+	if (!strcmp(val, "LOCAL7")) {
+		*conf = LOG_LOCAL7;
+		return NULL;
+	}
+#endif
+
+	return "invalid value";
+}
+/* }}} */
+#endif
+
 static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset) /* {{{ */
 {
 	char *val = Z_STRVAL_P(value);
@@ -495,18 +673,29 @@
 		}
 
 		if (wp->config->request_slowlog_timeout && wp->config->slowlog && *wp->config->slowlog) {
-			int fd;
+#ifdef HAVE_SYSLOG_H
+			if (!strcasecmp(wp->config->slowlog, "syslog")) {
+				wp->config->slowlog_syslog = 1;
+				if (wp->config->slowlog_syslog_level <= 0) {
+					wp->config->slowlog_syslog_level = ZLOG_DEBUG;
+				}
+				wp->config->slowlog_syslog_level = syslog_priorities[wp->config->slowlog_syslog_level];
+			} else
+#endif
+			{
+				int fd;
 
-			fpm_evaluate_full_path(&wp->config->slowlog);
+				fpm_evaluate_full_path(&wp->config->slowlog);
 
-			if (wp->config->request_slowlog_timeout) {
-				fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
+				if (wp->config->request_slowlog_timeout) {
+					fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
 
-				if (0 > fd) {
-					zlog(ZLOG_STUFF, ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog);
-					return -1;
+					if (0 > fd) {
+						zlog(ZLOG_STUFF, ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog);
+						return -1;
+					}
+					close(fd);
 				}
-				close(fd);
 			}
 		}
 
@@ -670,6 +859,18 @@
 		fpm_evaluate_full_path(&fpm_global_config.pid_file);
 	}
 
+#ifdef HAVE_SYSLOG_H
+	if (!fpm_global_config.syslog_ident) {
+		fpm_global_config.syslog_ident = strdup("fpm");
+	}
+
+	if (fpm_global_config.syslog_facility < 0) {
+		fpm_global_config.syslog_facility = LOG_DAEMON;
+	}
+#endif
+
+	fpm_globals.log_level = fpm_global_config.log_level;
+
 	if (!fpm_global_config.error_log) {
 		char *tmp_log_path;
 
@@ -678,7 +879,12 @@
 		efree(tmp_log_path);
 	}
 
-	fpm_evaluate_full_path(&fpm_global_config.error_log);
+#ifdef HAVE_SYSLOG_H
+	if (strcasecmp(fpm_global_config.error_log, "syslog") != 0)
+#endif
+	{
+		fpm_evaluate_full_path(&fpm_global_config.error_log);
+	}
 
 	if (0 > fpm_stdio_open_error_log(0)) {
 		return -1;
@@ -694,6 +900,11 @@
 	free(fpm_global_config.error_log);
 	fpm_global_config.pid_file = 0;
 	fpm_global_config.error_log = 0;
+
+#ifdef HAVE_SYSLOG_H
+	free(fpm_global_config.syslog_ident);
+	fpm_global_config.syslog_ident = 0;
+#endif
 }
 /* }}} */
 
diff -Naur ../1/sapi/fpm/fpm/fpm_conf.h sapi/fpm/fpm/fpm_conf.h
--- ../1/sapi/fpm/fpm/fpm_conf.h	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/fpm_conf.h	2010-07-07 09:35:10.000000000 +0200
@@ -25,6 +25,11 @@
 	int daemonize;
 	char *pid_file;
 	char *error_log;
+	int log_level;
+#ifdef HAVE_SYSLOG_H
+	char *syslog_ident;
+	int syslog_facility;
+#endif
 };
 
 extern struct fpm_global_config_s fpm_global_config;
@@ -38,6 +43,10 @@
 	int request_terminate_timeout;
 	int request_slowlog_timeout;
 	char *slowlog;
+#ifdef HAVE_SYSLOG_H
+	int slowlog_syslog;
+	int slowlog_syslog_level;
+#endif
 	int rlimit_files;
 	int rlimit_core;
 	int catch_workers_output;
diff -Naur ../1/sapi/fpm/fpm/fpm_php_trace.c sapi/fpm/fpm/fpm_php_trace.c
--- ../1/sapi/fpm/fpm/fpm_php_trace.c	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/fpm_php_trace.c	2010-07-07 09:49:20.000000000 +0200
@@ -8,6 +8,7 @@
 
 #include "php.h"
 #include "php_main.h"
+#include "php_syslog.h"
 
 #include <stdio.h>
 #include <stddef.h>
@@ -53,13 +54,27 @@
 
 	zlog_print_time(&tv, buf, buf_size);
 
-	fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
+#ifdef HAVE_SYSLOG_H
+	if (child->wp->config->slowlog_syslog) {
+		syslog(child->wp->config->slowlog_syslog_level, "[pool %s] pid %d", child->wp->config->name, (int) pid);
+	} else
+#endif
+	{
+		fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
+	}
 
 	if (0 > fpm_trace_get_strz(buf, buf_size, (long) &SG(request_info).path_translated)) {
 		return -1;
 	}
 
-	fprintf(slowlog, "script_filename = %s\n", buf);
+#ifdef HAVE_SYSLOG_H
+	if (child->wp->config->slowlog_syslog) {
+		syslog(child->wp->config->slowlog_syslog_level, "script_filename = %s", buf);
+	} else
+#endif
+	{
+		fprintf(slowlog, "script_filename = %s\n", buf);
+	}
 
 	if (0 > fpm_trace_get_long((long) &EG(current_execute_data), &l)) {
 		return -1;
@@ -70,8 +85,21 @@
 	while (execute_data) {
 		long function;
 		uint lineno = 0;
+#ifdef HAVE_SYSLOG_H
+		char out1[1024 + 1];
+		char out2[1024 + 1];
+
+		out1[0] = out2[0] = '\0';
+#endif
 
-		fprintf(slowlog, "[0x%" PTR_FMT "lx] ", execute_data);
+#ifdef HAVE_SYSLOG_H
+		if (child->wp->config->slowlog_syslog) {
+			snprintf(out1, 1024, "[0x%" PTR_FMT "lx] ", execute_data);
+		} else
+#endif
+		{
+			fprintf(slowlog, "[0x%" PTR_FMT "lx] ", execute_data);
+		}
 
 		if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, function_state.function), &l)) {
 			return -1;
@@ -84,9 +112,23 @@
 				return -1;
 			}
 
-			fprintf(slowlog, "%s()", buf);
+#ifdef HAVE_SYSLOG_H
+			if (child->wp->config->slowlog_syslog) {
+				snprintf(out2, 1024, "%s()", buf);
+			} else
+#endif
+			{
+				fprintf(slowlog, "%s()", buf);
+			}
 		} else {
-			fprintf(slowlog, "???");
+#ifdef HAVE_SYSLOG_H
+			if (child->wp->config->slowlog_syslog) {
+				snprintf(out2, 1024, "????");
+			} else
+#endif
+			{
+				fprintf(slowlog, "???");
+			}
 		}
 
 		if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, op_array), &l)) {
@@ -118,7 +160,14 @@
 			lineno = *lu;
 		}
 
-		fprintf(slowlog, " %s:%u\n", *buf ? buf : "unknown", lineno);
+#ifdef HAVE_SYSLOG_H
+		if (child->wp->config->slowlog_syslog) {
+			syslog(child->wp->config->slowlog_syslog_level, "%s\n%s\n %s:%u", out1, out2, *buf ? buf : "unknown", lineno);
+		} else
+#endif
+		{
+			fprintf(slowlog, " %s:%u\n", *buf ? buf : "unknown", lineno);
+		}
 
 		if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) {
 			return -1;
@@ -137,15 +186,20 @@
 void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
 {
 	TSRMLS_FETCH();
-	FILE *slowlog;
+	FILE *slowlog = NULL;
 
 	zlog(ZLOG_STUFF, ZLOG_NOTICE, "about to trace %d", (int) child->pid);
 
-	slowlog = fopen(child->wp->config->slowlog, "a+");
+#ifdef HAVE_SYSLOG_H
+	if (!child->wp->config->slowlog_syslog)
+#endif
+	{
+		slowlog = fopen(child->wp->config->slowlog, "a+");
 
-	if (!slowlog) {
-		zlog(ZLOG_STUFF, ZLOG_SYSERROR, "fopen(%s) failed", child->wp->config->slowlog);
-		goto done0;
+		if (!slowlog) {
+			zlog(ZLOG_STUFF, ZLOG_SYSERROR, "fopen(%s) failed", child->wp->config->slowlog);
+			goto done0;
+		}
 	}
 
 	if (0 > fpm_trace_ready(child->pid)) {
@@ -153,7 +207,14 @@
 	}
 
 	if (0 > fpm_php_trace_dump(child, slowlog TSRMLS_CC)) {
-		fprintf(slowlog, "+++ dump failed\n");
+#ifdef HAVE_SYSLOG_H
+		if (child->wp->config->slowlog_syslog) {
+			syslog(child->wp->config->slowlog_syslog_level, "+++ dump failed");
+		} else
+#endif
+		{
+			fprintf(slowlog, "+++ dump failed\n");
+		}
 	}
 
 	if (0 > fpm_trace_close(child->pid)) {
@@ -161,7 +222,12 @@
 	}
 
 done1:
-	fclose(slowlog);
+#ifdef HAVE_SYSLOG_H
+	if (!child->wp->config->slowlog_syslog)
+#endif
+	{
+		fclose(slowlog);
+	}
 
 done0:
 	fpm_pctl_kill(child->pid, FPM_PCTL_CONT);
diff -Naur ../1/sapi/fpm/fpm/fpm_stdio.c sapi/fpm/fpm/fpm_stdio.c
--- ../1/sapi/fpm/fpm/fpm_stdio.c	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/fpm_stdio.c	2010-07-07 11:16:38.000000000 +0200
@@ -11,6 +11,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include "php_syslog.h"
+
 #include "fpm.h"
 #include "fpm_children.h"
 #include "fpm_events.h"
@@ -43,7 +45,7 @@
 {
 	zlog_set_level(fpm_globals.log_level);
 	if (fpm_global_config.daemonize) {
-		if (fpm_globals.error_log_fd != STDERR_FILENO) {
+		if (fpm_globals.error_log_fd >= 0) {
 			/* there might be messages to stderr from libevent, we need to log them all */
 			if (0 > dup2(fpm_globals.error_log_fd, STDERR_FILENO)) {
 				zlog(ZLOG_STUFF, ZLOG_SYSERROR, "dup2() failed");
@@ -58,7 +60,12 @@
 
 int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
 {
-	close(fpm_globals.error_log_fd);
+#ifdef HAVE_SYSLOG_H
+	if (fpm_globals.error_log_fd != ZLOG_SYSLOG)
+#endif
+	{
+		close(fpm_globals.error_log_fd);
+	}
 	fpm_globals.error_log_fd = -1;
 	zlog_set_fd(-1);
 
@@ -235,6 +242,29 @@
 {
 	int fd;
 
+#ifdef HAVE_SYSLOG_H
+	{
+		struct fpm_worker_pool_s *wp;
+		int syslog_opened = 0;
+
+		for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
+			if (wp->config->slowlog_syslog) {
+				openlog(fpm_global_config.syslog_ident, LOG_PID | LOG_CONS, fpm_global_config.syslog_facility);
+				syslog_opened = 1;
+				break;
+			}
+		}
+
+		if (!strcasecmp(fpm_global_config.error_log, "syslog")) {
+			if (!syslog_opened) {
+				openlog(fpm_global_config.syslog_ident, LOG_PID | LOG_CONS, fpm_global_config.syslog_facility);
+			}
+			fpm_globals.error_log_fd = ZLOG_SYSLOG;
+			return 0;
+		}
+	}
+#endif
+
 	fd = open(fpm_global_config.error_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
 	if (0 > fd) {
 		zlog(ZLOG_STUFF, ZLOG_SYSERROR, "open(\"%s\") failed", fpm_global_config.error_log);
diff -Naur ../1/sapi/fpm/fpm/zlog.c sapi/fpm/fpm/zlog.c
--- ../1/sapi/fpm/fpm/zlog.c	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/zlog.c	2010-07-07 09:35:10.000000000 +0200
@@ -12,6 +12,8 @@
 #include <sys/time.h>
 #include <errno.h>
 
+#include "php_syslog.h"
+
 #include "zlog.h"
 
 #define MAX_LINE_LENGTH 1024
@@ -27,6 +29,16 @@
 	[ZLOG_ALERT]		= "ALERT",
 };
 
+#ifdef HAVE_SYSLOG_H
+const int syslog_priorities[] = {
+	[ZLOG_DEBUG]		= LOG_DEBUG,
+	[ZLOG_NOTICE]		= LOG_NOTICE,
+	[ZLOG_WARNING]		= LOG_WARNING,
+	[ZLOG_ERROR]		= LOG_ERR,
+	[ZLOG_ALERT]		= LOG_ALERT,
+};
+#endif
+
 size_t zlog_print_time(struct timeval *tv, char *timebuf, size_t timebuf_len) /* {{{ */
 {
 	struct tm t;
@@ -73,16 +85,29 @@
 	}
 
 	saved_errno = errno;
-	gettimeofday(&tv, 0);
-	len = zlog_print_time(&tv, buf, buf_size);
-	if (zlog_level == ZLOG_DEBUG) {
-		len += snprintf(buf + len, buf_size - len, " [%s] pid %d, %s(), line %d: ", level_names[flags & ZLOG_LEVEL_MASK], getpid(), function, line);
-	} else {
-		len += snprintf(buf + len, buf_size - len, " [%s] ", level_names[flags & ZLOG_LEVEL_MASK]);
-	}
 
-	if (len > buf_size - 1) {
-		truncated = 1;
+#ifdef HAVE_SYSLOG_H
+	if (zlog_fd == ZLOG_SYSLOG) {
+		len = 0;
+		if (zlog_level == ZLOG_DEBUG) {
+			len = snprintf(buf, buf_size, "[%s] %s(), line %d: ", level_names[flags & ZLOG_LEVEL_MASK], function, line);
+		} else {
+			len += snprintf(buf, buf_size, "[%s] ", level_names[flags & ZLOG_LEVEL_MASK]);
+		}
+	} else 
+#endif
+	{
+		gettimeofday(&tv, 0);
+		len = zlog_print_time(&tv, buf, buf_size);
+		if (zlog_level == ZLOG_DEBUG) {
+			len += snprintf(buf + len, buf_size - len, " [%s] pid %d, %s(), line %d: ", level_names[flags & ZLOG_LEVEL_MASK], getpid(), function, line);
+		} else {
+			len += snprintf(buf + len, buf_size - len, " [%s] ", level_names[flags & ZLOG_LEVEL_MASK]);
+		}
+
+		if (len > buf_size - 1) {
+			truncated = 1;
+		}
 	}
 
 	if (!truncated) {
@@ -108,6 +133,13 @@
 		len = buf_size - 1;
 	}
 
+#ifdef HAVE_SYSLOG_H
+	if (zlog_fd == ZLOG_SYSLOG) {
+		syslog(syslog_priorities[zlog_level], "%s", buf);
+		return;
+	}
+#endif
+
 	buf[len++] = '\n';
 	write(zlog_fd > -1 ? zlog_fd : STDERR_FILENO, buf, len);
 }
diff -Naur ../1/sapi/fpm/fpm/zlog.h sapi/fpm/fpm/zlog.h
--- ../1/sapi/fpm/fpm/zlog.h	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/fpm/zlog.h	2010-07-07 09:35:10.000000000 +0200
@@ -7,6 +7,11 @@
 
 #define ZLOG_STUFF		__func__, __LINE__
 
+#ifdef HAVE_SYSLOG_H
+#define ZLOG_SYSLOG -2
+extern const int syslog_priorities[];
+#endif
+
 struct timeval;
 
 int zlog_set_fd(int new_fd);
diff -Naur ../1/sapi/fpm/php-fpm.conf.in sapi/fpm/php-fpm.conf.in
--- ../1/sapi/fpm/php-fpm.conf.in	2010-07-05 14:38:22.000000000 +0200
+++ sapi/fpm/php-fpm.conf.in	2010-07-07 12:10:40.000000000 +0200
@@ -20,9 +20,24 @@
 ;pid = @EXPANDED_LOCALSTATEDIR@/run/php-fpm.pid
 
 ; Error log file
+; If it's set to "syslog", log is sent to syslogd instead of being written
+; in a local file.
 ; Default Value: @EXPANDED_LOCALSTATEDIR@/log/php-fpm.log
 ;error_log = @EXPANDED_LOCALSTATEDIR@/log/php-fpm.log
 
+; syslog_facility is used to specify what type of program is logging the
+; message. This lets syslogd specify that messages from different facilities
+; will be handled differently.
+; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
+; Default Value: daemon
+;syslog_facility = daemon
+
+; syslog_ident is prepended to every message. If you have multiple FPM
+; instances running on the same server, you can change the default value
+; which must suit common needs.
+; Default Value: php-fpm
+;syslog_ident = php-fpm
+
 ; Log level
 ; Possible Values: alert, error, warning, notice, debug
 ; Default Value: notice
@@ -212,8 +227,15 @@
 ;request_slowlog_timeout = 0
  
 ; The log file for slow requests
+; If it's set to "syslog", log is sent to syslogd instead of being written
+; in a local file.
 ; Default Value: @EXPANDED_LOCALSTATEDIR@/log/php-fpm.log.slow
 ;slowlog = @EXPANDED_LOCALSTATEDIR@/log/php-fpm.log.slow
+
+; slowlog_syslog_level
+; It takes the same values as log_level
+; Default Value: debug
+;slowlog_syslog_level = debug
  
 ; Set open file descriptor rlimit.
 ; Default Value: system defined value
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC