You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
20 KiB

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