php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch fpm-syslog.v5.patch for FPM related Bug #52052Patch version 2011-01-28 14:48 UTC Return to Bug #52052 | Download this patchThis patch renders other patches obsolete Obsolete patches:
Developer: ef-lists@email.deIndex: sapi/fpm/php-fpm.conf.in =================================================================== --- sapi/fpm/php-fpm.conf.in (revision 307820) +++ sapi/fpm/php-fpm.conf.in (working copy) @@ -25,10 +25,25 @@ ;pid = 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. ; Note: the default prefix is @EXPANDED_LOCALSTATEDIR@ ; Default Value: log/php-fpm.log ;error_log = 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 @@ -237,10 +252,17 @@ ;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: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set ;slowlog = log/$pool.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 ;rlimit_files = 1024 Index: sapi/fpm/fpm/fpm_php_trace.c =================================================================== --- sapi/fpm/fpm/fpm_php_trace.c (revision 307820) +++ sapi/fpm/fpm/fpm_php_trace.c (working copy) @@ -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) { + php_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) { + php_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) { + php_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_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_SYSERROR, "fopen(%s) failed", child->wp->config->slowlog); - goto done0; + if (!slowlog) { + zlog(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) { + php_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); Index: sapi/fpm/fpm/fpm_stdio.c =================================================================== --- sapi/fpm/fpm/fpm_stdio.c (revision 307820) +++ sapi/fpm/fpm/fpm_stdio.c (working copy) @@ -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" @@ -42,7 +44,7 @@ int fpm_stdio_init_final() /* {{{ */ { 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_SYSERROR, "dup2() failed"); @@ -57,7 +59,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); @@ -249,6 +256,32 @@ { 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; + if (fpm_global_config.daemonize) { + zlog_set_fd(fpm_globals.error_log_fd); + } + 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_SYSERROR, "open(\"%s\") failed", fpm_global_config.error_log); Index: sapi/fpm/fpm/fpm_conf.c =================================================================== --- sapi/fpm/fpm/fpm_conf.c (revision 307820) +++ sapi/fpm/fpm/fpm_conf.c (working copy) @@ -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,16 @@ 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 = { .daemonize = 1 }; +struct fpm_global_config_s fpm_global_config = { + .daemonize = 1 +#ifdef HAVE_SYSLOG_H + , .syslog_facility = -1 +#endif +}; static struct fpm_worker_pool_s *current_wp = NULL; static int ini_recursion = 0; static char *ini_filename = NULL; @@ -69,7 +78,11 @@ { "daemonize", &fpm_conf_set_boolean, GO(daemonize) }, { "pid", &fpm_conf_set_string, GO(pid_file) }, { "error_log", &fpm_conf_set_string, GO(error_log) }, - { "log_level", &fpm_conf_set_log_level, 0 }, + { "log_level", &fpm_conf_set_log_level, GO(log_level) }, +#ifdef HAVE_SYSLOG_H + { "syslog_ident", &fpm_conf_set_string, GO(syslog_ident) }, + { "syslog_facility", &fpm_conf_set_syslog_facility, GO(syslog_facility) }, +#endif { 0, 0, 0 } }; @@ -82,6 +95,9 @@ { "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) }, { "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) }, { "slowlog", &fpm_conf_set_string, WPO(slowlog) }, +#ifdef HAVE_SYSLOG_H + { "slowlog_syslog_level", &fpm_conf_set_log_level, WPO(slowlog_syslog_level) }, +#endif { "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) }, { "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) }, { "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) }, @@ -233,25 +249,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 (!strcasecmp(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 (!strcasecmp(val, "UUCP")) { + *conf = LOG_UUCP; + return NULL; + } +#endif + +#ifdef LOG_LOCAL0 + if (!strcasecmp(val, "LOCAL0")) { + *conf = LOG_LOCAL0; + return NULL; + } +#endif + +#ifdef LOG_LOCAL1 + if (!strcasecmp(val, "LOCAL1")) { + *conf = LOG_LOCAL1; + return NULL; + } +#endif + +#ifdef LOG_LOCAL2 + if (!strcasecmp(val, "LOCAL2")) { + *conf = LOG_LOCAL2; + return NULL; + } +#endif + +#ifdef LOG_LOCAL3 + if (!strcasecmp(val, "LOCAL3")) { + *conf = LOG_LOCAL3; + return NULL; + } +#endif + +#ifdef LOG_LOCAL4 + if (!strcasecmp(val, "LOCAL4")) { + *conf = LOG_LOCAL4; + return NULL; + } +#endif + +#ifdef LOG_LOCAL5 + if (!strcasecmp(val, "LOCAL5")) { + *conf = LOG_LOCAL5; + return NULL; + } +#endif + +#ifdef LOG_LOCAL6 + if (!strcasecmp(val, "LOCAL6")) { + *conf = LOG_LOCAL6; + return NULL; + } +#endif + +#ifdef LOG_LOCAL7 + if (!strcasecmp(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); @@ -559,7 +728,12 @@ } if (wp->config->slowlog && *wp->config->slowlog) { - fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0); +#ifdef HAVE_SYSLOG_H + if (strcasecmp(wp->config->slowlog, "syslog") != 0) +#endif + { + fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0); + } } if (wp->config->request_slowlog_timeout) { @@ -580,15 +754,27 @@ #endif if (wp->config->slowlog && *wp->config->slowlog) { - int fd; +#ifdef HAVE_SYSLOG_H + if (strcasecmp(wp->config->slowlog, "syslog") == 0) { + 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; - fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); + fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); - if (0 > fd) { - zlog(ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog); - return -1; + if (0 > fd) { + zlog(ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog); + return -1; + } + close(fd); } - close(fd); } } @@ -774,11 +960,28 @@ fpm_evaluate_full_path(&fpm_global_config.pid_file, NULL, PHP_LOCALSTATEDIR, 0); } +#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) { fpm_global_config.error_log = strdup("log/php-fpm.log"); } - fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0); +#ifdef HAVE_SYSLOG_H + if (strcasecmp(fpm_global_config.error_log, "syslog") != 0) +#endif + { + fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0); + } if (0 > fpm_stdio_open_error_log(0)) { return -1; @@ -794,6 +997,10 @@ 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 free(fpm_globals.config); } /* }}} */ @@ -1114,6 +1321,10 @@ zlog(ZLOG_NOTICE, "\tdaemonize = %s", BOOL2STR(fpm_global_config.daemonize)); zlog(ZLOG_NOTICE, "\terror_log = %s", STR2STR(fpm_global_config.error_log)); zlog(ZLOG_NOTICE, "\tlog_level = %s", zlog_get_level_name()); +#ifdef HAVE_SYSLOG_H + zlog(ZLOG_NOTICE, "\tsyslog_ident = %s", STR2STR(fpm_global_config.syslog_ident)); + zlog(ZLOG_NOTICE, "\tsyslog_facility = %d", fpm_global_config.syslog_facility); +#endif zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout); zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval); zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold); @@ -1147,6 +1358,10 @@ zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout); zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout); zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog)); +#ifdef HAVE_SYSLOG_H + zlog(ZLOG_NOTICE, "\tslowlog_syslog = %d", wp->config->slowlog_syslog); + zlog(ZLOG_NOTICE, "\tslowlog_syslog_level = %d", wp->config->slowlog_syslog_level); +#endif zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files); zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core); Index: sapi/fpm/fpm/fpm_conf.h =================================================================== --- sapi/fpm/fpm/fpm_conf.h (revision 307820) +++ sapi/fpm/fpm/fpm_conf.h (working copy) @@ -29,6 +29,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; @@ -43,6 +48,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; Index: sapi/fpm/fpm/zlog.c =================================================================== --- sapi/fpm/fpm/zlog.c (revision 307820) +++ sapi/fpm/fpm/zlog.c (working copy) @@ -12,6 +12,8 @@ #include <sys/time.h> #include <errno.h> +#include "php_syslog.h" + #include "zlog.h" #define MAX_LINE_LENGTH 1024 @@ -28,6 +30,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 + const char *zlog_get_level_name() /* {{{ */ { return level_names[zlog_level]; @@ -84,16 +96,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) { @@ -119,9 +144,18 @@ len = buf_size - 1; } - buf[len++] = '\n'; - write(zlog_fd > -1 ? zlog_fd : STDERR_FILENO, buf, len); - if (zlog_fd != STDERR_FILENO && zlog_fd > -1 && !launched && (flags & ZLOG_LEVEL_MASK) >= ZLOG_NOTICE) { +#ifdef HAVE_SYSLOG_H + if (zlog_fd == ZLOG_SYSLOG) { + buf[len] = '\0'; + php_syslog(syslog_priorities[zlog_level], "%s", buf); + buf[len++] = '\n'; + } else +#endif + { + buf[len++] = '\n'; + write(zlog_fd > -1 ? zlog_fd : STDERR_FILENO, buf, len); + } + if (zlog_fd != STDERR_FILENO && zlog_fd != -1 && !launched && (flags & ZLOG_LEVEL_MASK) >= ZLOG_NOTICE) { write(STDERR_FILENO, buf, len); } } Index: sapi/fpm/fpm/zlog.h =================================================================== --- sapi/fpm/fpm/zlog.h (revision 307820) +++ sapi/fpm/fpm/zlog.h (working copy) @@ -9,6 +9,11 @@ struct timeval; +#ifdef HAVE_SYSLOG_H +#define ZLOG_SYSLOG -2 +extern const int syslog_priorities[]; +#endif + int zlog_set_fd(int new_fd); int zlog_set_level(int new_value); const char *zlog_get_level_name(); |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sat Dec 21 18:01:29 2024 UTC |