Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #2 from Adalan/master

Updated the patch file with a slight modification for FreeBSD and Nginx Version 
Thanks to Adam Landry. See pull request:#2
  • Loading branch information...
commit 256183b4ea3476829c9ea580e1ec9966b834e076 2 parents afeea6d + c30e7ba
Weibin Yao(姚伟斌) authored

Showing 1 changed file with 690 additions and 0 deletions. Show diff stats Hide diff stats

  1. +690 0 freebsd_syslog_1.0.12.patch
690 freebsd_syslog_1.0.12.patch
... ... @@ -0,0 +1,690 @@
  1 +diff --git src/core/ngx_cycle.c b/src/core/ngx_cycle.c
  2 +index 7986707..9902ef7 100644
  3 +--- src/core/ngx_cycle.c
  4 ++++ b/src/core/ngx_cycle.c
  5 +@@ -84,6 +84,12 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
  6 + cycle->pool = pool;
  7 + cycle->log = log;
  8 + cycle->new_log.log_level = NGX_LOG_ERR;
  9 ++#if (NGX_ENABLE_SYSLOG)
  10 ++ cycle->new_log.facility = SYSLOG_FACILITY;
  11 ++ cycle->new_log.facility = ERR_SYSLOG_PRIORITY;
  12 ++ cycle->new_log.syslog_on = 0;
  13 ++ cycle->new_log.syslog_set = 0;
  14 ++#endif
  15 + cycle->old_cycle = old_cycle;
  16 +
  17 + cycle->conf_prefix.len = old_cycle->conf_prefix.len;
  18 +diff --git src/core/ngx_log.c b/src/core/ngx_log.c
  19 +index 4433314..b8641eb 100644
  20 +--- src/core/ngx_log.c
  21 ++++ b/src/core/ngx_log.c
  22 +@@ -9,6 +9,15 @@
  23 +
  24 +
  25 + static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
  26 ++#if (NGX_ENABLE_SYSLOG)
  27 ++static char *ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
  28 ++void log_exit(ngx_cycle_t *cycle);
  29 ++
  30 ++typedef struct{
  31 ++ ngx_str_t name;
  32 ++ ngx_int_t macro;
  33 ++} ngx_string_to_macro_t;
  34 ++#endif
  35 +
  36 +
  37 + static ngx_command_t ngx_errlog_commands[] = {
  38 +@@ -20,6 +29,15 @@ static ngx_command_t ngx_errlog_commands[] = {
  39 + 0,
  40 + NULL},
  41 +
  42 ++#if (NGX_ENABLE_SYSLOG)
  43 ++ {ngx_string("syslog"),
  44 ++ NGX_MAIN_CONF|NGX_CONF_TAKE12,
  45 ++ ngx_set_syslog,
  46 ++ 0,
  47 ++ 0,
  48 ++ NULL},
  49 ++#endif
  50 ++
  51 + ngx_null_command
  52 + };
  53 +
  54 +@@ -42,7 +60,11 @@ ngx_module_t ngx_errlog_module = {
  55 + NULL, /* init thread */
  56 + NULL, /* exit thread */
  57 + NULL, /* exit process */
  58 +- NULL, /* exit master */
  59 ++#if (NGX_ENABLE_SYSLOG)
  60 ++ log_exit, /* exit master */
  61 ++#else
  62 ++ NULL,
  63 ++#endif
  64 + NGX_MODULE_V1_PADDING
  65 + };
  66 +
  67 +@@ -51,6 +73,48 @@ static ngx_log_t ngx_log;
  68 + static ngx_open_file_t ngx_log_file;
  69 + ngx_uint_t ngx_use_stderr = 1;
  70 +
  71 ++#if (NGX_ENABLE_SYSLOG)
  72 ++static ngx_string_to_macro_t ngx_syslog_facilities[] = {
  73 ++ {ngx_string("auth"), LOG_AUTH},
  74 ++#if !(NGX_SOLARIS)
  75 ++ {ngx_string("authpriv"), LOG_AUTHPRIV},
  76 ++#endif
  77 ++ {ngx_string("cron"), LOG_CRON},
  78 ++ {ngx_string("daemon"), LOG_DAEMON},
  79 ++#if !(NGX_SOLARIS)
  80 ++ {ngx_string("ftp"), LOG_FTP},
  81 ++#endif
  82 ++ {ngx_string("kern"), LOG_KERN},
  83 ++ {ngx_string("local0"), LOG_LOCAL0},
  84 ++ {ngx_string("local1"), LOG_LOCAL1},
  85 ++ {ngx_string("local2"), LOG_LOCAL2},
  86 ++ {ngx_string("local3"), LOG_LOCAL3},
  87 ++ {ngx_string("local4"), LOG_LOCAL4},
  88 ++ {ngx_string("local5"), LOG_LOCAL5},
  89 ++ {ngx_string("local6"), LOG_LOCAL6},
  90 ++ {ngx_string("local7"), LOG_LOCAL7},
  91 ++ {ngx_string("lpr"), LOG_LPR},
  92 ++ {ngx_string("mail"), LOG_MAIL},
  93 ++ {ngx_string("news"), LOG_NEWS},
  94 ++ {ngx_string("syslog"), LOG_SYSLOG},
  95 ++ {ngx_string("user"), LOG_USER},
  96 ++ {ngx_string("uucp"), LOG_UUCP},
  97 ++ { ngx_null_string, 0}
  98 ++};
  99 ++
  100 ++static ngx_string_to_macro_t ngx_syslog_priorities[] = {
  101 ++ {ngx_string("emerg"), LOG_EMERG},
  102 ++ {ngx_string("alert"), LOG_ALERT},
  103 ++ {ngx_string("crit"), LOG_CRIT},
  104 ++ {ngx_string("error"), LOG_ERR},
  105 ++ {ngx_string("err"), LOG_ERR},
  106 ++ {ngx_string("warn"), LOG_WARNING},
  107 ++ {ngx_string("notice"),LOG_NOTICE},
  108 ++ {ngx_string("info"), LOG_INFO},
  109 ++ {ngx_string("debug"), LOG_DEBUG},
  110 ++ { ngx_null_string, 0}
  111 ++};
  112 ++#endif
  113 +
  114 + static ngx_str_t err_levels[] = {
  115 + ngx_null_string,
  116 +@@ -88,11 +152,16 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
  117 + va_list args;
  118 + #endif
  119 + u_char *p, *last, *msg;
  120 ++#if (NGX_ENABLE_SYSLOG)
  121 ++ u_char *errstr_syslog;
  122 ++#endif
  123 + u_char errstr[NGX_MAX_ERROR_STR];
  124 +
  125 ++#if !(NGX_ENABLE_SYSLOG)
  126 + if (log->file->fd == NGX_INVALID_FILE) {
  127 + return;
  128 + }
  129 ++#endif
  130 +
  131 + last = errstr + NGX_MAX_ERROR_STR;
  132 +
  133 +@@ -101,6 +170,10 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
  134 +
  135 + p = errstr + ngx_cached_err_log_time.len;
  136 +
  137 ++#if (NGX_ENABLE_SYSLOG)
  138 ++ errstr_syslog = p;
  139 ++#endif
  140 ++
  141 + p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
  142 +
  143 + /* pid#tid */
  144 +@@ -139,11 +212,27 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
  145 +
  146 + ngx_linefeed(p);
  147 +
  148 ++#if (NGX_ENABLE_SYSLOG)
  149 ++ if (log->file != NULL && log->file->name.len != 0) {
  150 ++ (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
  151 ++ }
  152 ++
  153 ++ /* Don't send the debug level info to syslog */
  154 ++ if (log->syslog_on && level < NGX_LOG_DEBUG) {
  155 ++ /* write to syslog */
  156 ++ syslog(log->priority, "%.*s", (int)(p - errstr_syslog), errstr_syslog);
  157 ++ }
  158 ++#else
  159 + (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
  160 ++#endif
  161 +
  162 + if (!ngx_use_stderr
  163 + || level > NGX_LOG_WARN
  164 ++#if (NGX_ENABLE_SYSLOG)
  165 ++ || (log->file != NULL && log->file->fd == ngx_stderr))
  166 ++#else
  167 + || log->file->fd == ngx_stderr)
  168 ++#endif
  169 + {
  170 + return;
  171 + }
  172 +@@ -364,6 +453,50 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
  173 +
  174 + return log;
  175 + }
  176 ++
  177 ++
  178 ++#if (NGX_ENABLE_SYSLOG)
  179 ++ngx_int_t
  180 ++ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority)
  181 ++{
  182 ++ ngx_int_t p = 0;
  183 ++ ngx_uint_t n, match = 0;
  184 ++
  185 ++ for (n = 0; ngx_syslog_priorities[n].name.len != 0; n++) {
  186 ++ if (ngx_strncmp(priority->data, ngx_syslog_priorities[n].name.data,
  187 ++ ngx_syslog_priorities[n].name.len) == 0) {
  188 ++ p = ngx_syslog_priorities[n].macro;
  189 ++ match = 1;
  190 ++ }
  191 ++ }
  192 ++
  193 ++ if (!match) {
  194 ++ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  195 ++ "invalid syslog priority \"%V\"", priority);
  196 ++ return -1;
  197 ++ }
  198 ++
  199 ++ return p;
  200 ++}
  201 ++
  202 ++
  203 ++char *
  204 ++ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log)
  205 ++{
  206 ++ log->priority = ERR_SYSLOG_PRIORITY;
  207 ++
  208 ++ if (priority->len == 0) {
  209 ++ return NGX_CONF_OK;
  210 ++ }
  211 ++
  212 ++ log->priority = ngx_log_get_priority(cf, priority);
  213 ++ if (log->priority == (-1)) {
  214 ++ return NGX_CONF_ERROR;
  215 ++ }
  216 ++
  217 ++ return NGX_CONF_OK;
  218 ++}
  219 ++#endif
  220 +
  221 +
  222 + char *
  223 +@@ -424,6 +557,13 @@ static char *
  224 + ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  225 + {
  226 + ngx_str_t *value, name;
  227 ++#if (NGX_ENABLE_SYSLOG)
  228 ++ u_char *off = NULL;
  229 ++ ngx_str_t priority;
  230 ++
  231 ++ ngx_str_null(&name);
  232 ++ ngx_str_null(&priority);
  233 ++#endif
  234 +
  235 + if (cf->cycle->new_log.file) {
  236 + return "is duplicate";
  237 +@@ -431,7 +571,44 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  238 +
  239 + value = cf->args->elts;
  240 +
  241 ++#if (NGX_ENABLE_SYSLOG)
  242 ++ if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
  243 ++ if (!cf->cycle->new_log.syslog_set) {
  244 ++ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  245 ++ "You must set the syslog directive and enable it first.");
  246 ++ return NGX_CONF_ERROR;
  247 ++ }
  248 ++
  249 ++ cf->cycle->new_log.syslog_on = 1;
  250 ++
  251 ++ if (value[1].data[sizeof("syslog") - 1] == ':') {
  252 ++ priority.len = value[1].len - sizeof("syslog");
  253 ++ priority.data = value[1].data + sizeof("syslog");
  254 ++
  255 ++ off = (u_char *)ngx_strchr(priority.data, (int) '|');
  256 ++ if (off != NULL) {
  257 ++ priority.len = off - priority.data;
  258 ++
  259 ++ off++;
  260 ++ name.len = value[1].data + value[1].len - off;
  261 ++ name.data = off;
  262 ++ }
  263 ++ }
  264 ++ else {
  265 ++ if (value[1].len > sizeof("syslog")) {
  266 ++ name.len = value[1].len - sizeof("syslog");
  267 ++ name.data = value[1].data + sizeof("syslog");
  268 ++ }
  269 ++ }
  270 ++
  271 ++ if (ngx_log_set_priority(cf, &priority, &cf->cycle->new_log) == NGX_CONF_ERROR) {
  272 ++ return NGX_CONF_ERROR;
  273 ++ }
  274 ++ }
  275 ++ else if (ngx_strcmp(value[1].data, "stderr") == 0) {
  276 ++#else
  277 + if (ngx_strcmp(value[1].data, "stderr") == 0) {
  278 ++#endif
  279 + ngx_str_null(&name);
  280 +
  281 + } else {
  282 +@@ -452,3 +629,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  283 +
  284 + return ngx_log_set_levels(cf, &cf->cycle->new_log);
  285 + }
  286 ++
  287 ++
  288 ++#if (NGX_ENABLE_SYSLOG)
  289 ++
  290 ++#define SYSLOG_IDENT_NAME "nginx"
  291 ++
  292 ++static char *
  293 ++ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  294 ++{
  295 ++ char *program;
  296 ++ ngx_str_t *value;
  297 ++ ngx_int_t facility, match = 0;
  298 ++ ngx_uint_t n;
  299 ++
  300 ++ value = cf->args->elts;
  301 ++
  302 ++ if (cf->cycle->new_log.syslog_set) {
  303 ++ return "is duplicate";
  304 ++ }
  305 ++
  306 ++ cf->cycle->new_log.syslog_set = 1;
  307 ++
  308 ++ for (n = 0; ngx_syslog_facilities[n].name.len != 0; n++) {
  309 ++ if (ngx_strncmp(value[1].data, ngx_syslog_facilities[n].name.data,
  310 ++ ngx_syslog_facilities[n].name.len) == 0) {
  311 ++ facility = ngx_syslog_facilities[n].macro;
  312 ++ match = 1;
  313 ++ break;
  314 ++ }
  315 ++ }
  316 ++
  317 ++ if (match) {
  318 ++ cf->cycle->new_log.facility = facility;
  319 ++ cf->cycle->new_log.priority = ERR_SYSLOG_PRIORITY;
  320 ++ }
  321 ++ else {
  322 ++ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  323 ++ "invalid syslog facility \"%V\"", &value[1]);
  324 ++ return NGX_CONF_ERROR;
  325 ++ }
  326 ++
  327 ++ program = SYSLOG_IDENT_NAME;
  328 ++ if (cf->args->nelts > 2) {
  329 ++ program = (char *) value[2].data;
  330 ++ }
  331 ++
  332 ++ openlog(program, LOG_ODELAY, facility);
  333 ++
  334 ++ return NGX_CONF_OK;
  335 ++}
  336 ++
  337 ++
  338 ++void log_exit(ngx_cycle_t *cycle)
  339 ++{
  340 ++ if (cycle->new_log.syslog_set) {
  341 ++ closelog();
  342 ++ }
  343 ++}
  344 ++#endif
  345 ++
  346 +diff --git src/core/ngx_log.h b/src/core/ngx_log.h
  347 +index 1054836..14288ee 100644
  348 +--- src/core/ngx_log.h
  349 ++++ b/src/core/ngx_log.h
  350 +@@ -11,6 +11,13 @@
  351 + #include <ngx_config.h>
  352 + #include <ngx_core.h>
  353 +
  354 ++#if (NGX_ENABLE_SYSLOG)
  355 ++#include <syslog.h>
  356 ++
  357 ++#define SYSLOG_FACILITY LOG_LOCAL5
  358 ++#define ERR_SYSLOG_PRIORITY LOG_ERR
  359 ++#endif
  360 ++
  361 +
  362 + #define NGX_LOG_STDERR 0
  363 + #define NGX_LOG_EMERG 1
  364 +@@ -60,6 +67,13 @@ struct ngx_log_s {
  365 + */
  366 +
  367 + char *action;
  368 ++
  369 ++#if (NGX_ENABLE_SYSLOG)
  370 ++ ngx_int_t priority;
  371 ++ ngx_int_t facility;
  372 ++ unsigned syslog_on:1; /* unsigned :1 syslog_on */
  373 ++ unsigned syslog_set:1; /*unsigned :1 syslog_set */
  374 ++#endif
  375 + };
  376 +
  377 +
  378 +@@ -197,6 +211,10 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
  379 +
  380 + ngx_log_t *ngx_log_init(u_char *prefix);
  381 + ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
  382 ++#if (NGX_ENABLE_SYSLOG)
  383 ++ngx_int_t ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority);
  384 ++char * ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log);
  385 ++#endif
  386 + char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
  387 + void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
  388 + void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
  389 +diff --git src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
  390 +index e6a7fdb..51c4384 100644
  391 +--- src/http/modules/ngx_http_log_module.c
  392 ++++ b/src/http/modules/ngx_http_log_module.c
  393 +@@ -8,6 +8,11 @@
  394 + #include <ngx_core.h>
  395 + #include <ngx_http.h>
  396 +
  397 ++#if (NGX_ENABLE_SYSLOG)
  398 ++#include <syslog.h>
  399 ++
  400 ++#define HTTP_SYSLOG_PRIORITY LOG_NOTICE
  401 ++#endif
  402 +
  403 + typedef struct ngx_http_log_op_s ngx_http_log_op_t;
  404 +
  405 +@@ -51,6 +56,11 @@ typedef struct {
  406 + time_t disk_full_time;
  407 + time_t error_log_time;
  408 + ngx_http_log_fmt_t *format;
  409 ++
  410 ++#if (NGX_ENABLE_SYSLOG)
  411 ++ ngx_int_t priority;
  412 ++ unsigned syslog_on:1; /* unsigned :1 syslog_on */
  413 ++#endif
  414 + } ngx_http_log_t;
  415 +
  416 +
  417 +@@ -318,11 +328,27 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
  418 + time_t now;
  419 + ssize_t n;
  420 + ngx_err_t err;
  421 +-
  422 ++
  423 ++#if (NGX_ENABLE_SYSLOG)
  424 ++ n = 0;
  425 ++ if (log->syslog_on) {
  426 ++ syslog(log->priority, "%.*s", (int)len, buf);
  427 ++ }
  428 ++#endif
  429 ++
  430 + if (log->script == NULL) {
  431 + name = log->file->name.data;
  432 ++#if (NGX_ENABLE_SYSLOG)
  433 ++ if (name != NULL) {
  434 ++ n = ngx_write_fd(log->file->fd, buf, len);
  435 ++ }
  436 ++ else {
  437 ++ n = len;
  438 ++ }
  439 ++#else
  440 + n = ngx_write_fd(log->file->fd, buf, len);
  441 +
  442 ++#endif
  443 + } else {
  444 + name = NULL;
  445 + n = ngx_http_log_script_write(r, log->script, &name, buf, len);
  446 +@@ -836,6 +862,10 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
  447 + log->script = NULL;
  448 + log->disk_full_time = 0;
  449 + log->error_log_time = 0;
  450 ++#if (NGX_ENABLE_SYSLOG)
  451 ++ log->priority = HTTP_SYSLOG_PRIORITY;
  452 ++ log->syslog_on = 0;
  453 ++#endif
  454 +
  455 + lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
  456 + fmt = lmcf->formats.elts;
  457 +@@ -861,6 +891,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  458 + ngx_http_log_main_conf_t *lmcf;
  459 + ngx_http_script_compile_t sc;
  460 +
  461 ++#if (NGX_ENABLE_SYSLOG)
  462 ++ u_char *off;
  463 ++ ngx_str_t priority;
  464 ++ ngx_uint_t syslog_on = 0;
  465 ++ name = priority = (ngx_str_t)ngx_null_string;
  466 ++#endif
  467 ++
  468 + value = cf->args->elts;
  469 +
  470 + if (ngx_strcmp(value[1].data, "off") == 0) {
  471 +@@ -873,6 +910,38 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  472 + "invalid parameter \"%V\"", &value[2]);
  473 + return NGX_CONF_ERROR;
  474 + }
  475 ++#if (NGX_ENABLE_SYSLOG)
  476 ++ else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
  477 ++ if (!cf->cycle->new_log.syslog_set) {
  478 ++ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  479 ++ "You must set the syslog directive and enable it first.");
  480 ++ return NGX_CONF_ERROR;
  481 ++ }
  482 ++
  483 ++ syslog_on = 1;
  484 ++ if (value[1].data[sizeof("syslog") - 1] == ':') {
  485 ++ priority.len = value[1].len - sizeof("syslog");
  486 ++ priority.data = value[1].data + sizeof("syslog");
  487 ++
  488 ++ off = (u_char*) ngx_strchr(priority.data, '|');
  489 ++ if (off != NULL) {
  490 ++ priority.len = off - priority.data;
  491 ++
  492 ++ off++;
  493 ++ name.len = value[1].data + value[1].len - off;
  494 ++ name.data = off;
  495 ++ }
  496 ++ }
  497 ++ else {
  498 ++ if (value[1].len > sizeof("syslog")) {
  499 ++ name.len = value[1].len - sizeof("syslog");
  500 ++ name.data = value[1].data + sizeof("syslog");
  501 ++ }
  502 ++ }
  503 ++ } else {
  504 ++ name = value[1];
  505 ++ }
  506 ++#endif
  507 +
  508 + if (llcf->logs == NULL) {
  509 + llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
  510 +@@ -890,6 +959,52 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  511 +
  512 + ngx_memzero(log, sizeof(ngx_http_log_t));
  513 +
  514 ++#if (NGX_ENABLE_SYSLOG)
  515 ++ log->syslog_on = syslog_on;
  516 ++
  517 ++ if (priority.len == 0) {
  518 ++ log->priority = HTTP_SYSLOG_PRIORITY;
  519 ++ }
  520 ++ else {
  521 ++ log->priority = ngx_log_get_priority(cf, &priority);
  522 ++ }
  523 ++
  524 ++ if (name.len != 0) {
  525 ++ n = ngx_http_script_variables_count(&name);
  526 ++
  527 ++ if (n == 0) {
  528 ++ log->file = ngx_conf_open_file(cf->cycle, &name);
  529 ++ if (log->file == NULL) {
  530 ++ return NGX_CONF_ERROR;
  531 ++ }
  532 ++ } else {
  533 ++ if (ngx_conf_full_name(cf->cycle, &name, 0) != NGX_OK) {
  534 ++ return NGX_CONF_ERROR;
  535 ++ }
  536 ++ log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
  537 ++ if (log->script == NULL) {
  538 ++ return NGX_CONF_ERROR;
  539 ++ }
  540 ++ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
  541 ++ sc.cf = cf;
  542 ++ sc.source = &name;
  543 ++ sc.lengths = &log->script->lengths;
  544 ++ sc.values = &log->script->values;
  545 ++ sc.variables = n;
  546 ++ sc.complete_lengths = 1;
  547 ++ sc.complete_values = 1;
  548 ++ if (ngx_http_script_compile(&sc) != NGX_OK) {
  549 ++ return NGX_CONF_ERROR;
  550 ++ }
  551 ++ }
  552 ++ }
  553 ++ else {
  554 ++ log->file = ngx_conf_open_file(cf->cycle, &name);
  555 ++ if (log->file == NULL) {
  556 ++ return NGX_CONF_ERROR;
  557 ++ }
  558 ++ }
  559 ++#else
  560 + n = ngx_http_script_variables_count(&value[1]);
  561 +
  562 + if (n == 0) {
  563 +@@ -897,7 +1012,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  564 + if (log->file == NULL) {
  565 + return NGX_CONF_ERROR;
  566 + }
  567 +-
  568 ++
  569 + } else {
  570 + if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
  571 + return NGX_CONF_ERROR;
  572 +@@ -922,6 +1037,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  573 + return NGX_CONF_ERROR;
  574 + }
  575 + }
  576 ++#endif
  577 +
  578 + if (cf->args->nelts >= 3) {
  579 + name = value[2];
  580 +diff --git src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
  581 +index bbb9311..fc08c65 100644
  582 +--- src/http/ngx_http_core_module.c
  583 ++++ b/src/http/ngx_http_core_module.c
  584 +@@ -1410,6 +1410,9 @@ ngx_http_update_location_config(ngx_http_request_t *r)
  585 +
  586 + if (r == r->main) {
  587 + r->connection->log->file = clcf->error_log->file;
  588 ++#if (NGX_ENABLE_SYSLOG)
  589 ++ r->connection->log->priority = clcf->error_log->priority;
  590 ++#endif
  591 +
  592 + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
  593 + r->connection->log->log_level = clcf->error_log->log_level;
  594 +@@ -4440,17 +4443,72 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  595 +
  596 + ngx_str_t *value;
  597 +
  598 ++#if (NGX_ENABLE_SYSLOG)
  599 ++ u_char *off = NULL;
  600 ++ ngx_int_t syslog_on = 0;
  601 ++ ngx_str_t name, priority;
  602 ++
  603 ++ name = priority = (ngx_str_t) ngx_null_string;
  604 ++#endif
  605 ++
  606 + if (clcf->error_log) {
  607 + return "is duplicate";
  608 + }
  609 +
  610 + value = cf->args->elts;
  611 +
  612 ++#if (NGX_ENABLE_SYSLOG)
  613 ++ if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
  614 ++ if (!cf->cycle->new_log.syslog_set) {
  615 ++ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  616 ++ "You must set the syslog directive and enable it first.");
  617 ++ return NGX_CONF_ERROR;
  618 ++ }
  619 ++
  620 ++ syslog_on = 1;
  621 ++
  622 ++ if (value[1].data[sizeof("syslog") - 1] == ':') {
  623 ++ priority.len = value[1].len - sizeof("syslog");
  624 ++ priority.data = value[1].data + sizeof("syslog");
  625 ++
  626 ++ off = (u_char*) ngx_strchr(priority.data, '|');
  627 ++ if (off != NULL) {
  628 ++ priority.len = off - priority.data;
  629 ++
  630 ++ off++;
  631 ++ name.len = value[1].data + value[1].len - off;
  632 ++ name.data = off;
  633 ++ }
  634 ++ }
  635 ++ else {
  636 ++ if (value[1].len > sizeof("syslog")) {
  637 ++ name.len = value[1].len - sizeof("syslog");
  638 ++ name.data = value[1].data + sizeof("syslog");
  639 ++ }
  640 ++ }
  641 ++ } else {
  642 ++ name = value[1];
  643 ++ }
  644 ++
  645 ++ clcf->error_log = ngx_log_create(cf->cycle, &name);
  646 ++#else
  647 + clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
  648 ++#endif
  649 + if (clcf->error_log == NULL) {
  650 + return NGX_CONF_ERROR;
  651 + }
  652 +
  653 ++#if (NGX_ENABLE_SYSLOG)
  654 ++ if (syslog_on) {
  655 ++ clcf->error_log->syslog_on = 1;
  656 ++ if (ngx_log_set_priority(cf, &priority, clcf->error_log) == NGX_CONF_ERROR) {
  657 ++ return NGX_CONF_ERROR;
  658 ++ }
  659 ++ }
  660 ++
  661 ++ clcf->error_log->log_level = 0;
  662 ++#endif
  663 ++
  664 + if (cf->args->nelts == 2) {
  665 + clcf->error_log->log_level = NGX_LOG_ERR;
  666 + return NGX_CONF_OK;
  667 +diff --git src/http/ngx_http_request.c b/src/http/ngx_http_request.c
  668 +index d11b13e..f787e0a 100644
  669 +--- src/http/ngx_http_request.c
  670 ++++ b/src/http/ngx_http_request.c
  671 +@@ -432,6 +432,9 @@ ngx_http_init_request(ngx_event_t *rev)
  672 +
  673 + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  674 + c->log->file = clcf->error_log->file;
  675 ++#if (NGX_ENABLE_SYSLOG)
  676 ++ c->log->priority = clcf->error_log->priority;
  677 ++#endif
  678 + if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
  679 + c->log->log_level = clcf->error_log->log_level;
  680 + }
  681 +@@ -1765,6 +1768,9 @@ found:
  682 +
  683 + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  684 + r->connection->log->file = clcf->error_log->file;
  685 ++#if (NGX_ENABLE_SYSLOG)
  686 ++ r->connection->log->priority = clcf->error_log->priority;
  687 ++#endif
  688 +
  689 + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
  690 + r->connection->log->log_level = clcf->error_log->log_level file;

0 comments on commit 256183b

Please sign in to comment.
Something went wrong with that request. Please try again.