-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnginx-0007-logs-write-access-log-to-stderr.patch
85 lines (73 loc) · 2.97 KB
/
nginx-0007-logs-write-access-log-to-stderr.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From 1203558f07a960c885af4225109b6525ec06e55e Mon Sep 17 00:00:00 2001
From: myfreeer <[email protected]>
Date: Thu, 23 Jan 2020 10:40:30 +0800
Subject: [PATCH] logs: write access log to stderr
Affecting:
* ngx_http_log_module
* ngx_stream_log_module
---
src/http/modules/ngx_http_log_module.c | 21 +++++++++++++++++++--
src/stream/ngx_stream_log_module.c | 12 +++++++++++-
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index f7c4bd2..e6b73ce 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -1179,6 +1179,7 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_log_loc_conf_t *prev = parent;
ngx_http_log_loc_conf_t *conf = child;
+ ngx_str_t name;
ngx_http_log_t *log;
ngx_http_log_fmt_t *fmt;
@@ -1220,7 +1221,13 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
if (log->file == NULL) {
- return NGX_CONF_ERROR;
+ // fall back to stderr
+ ngx_str_null(&name);
+ cf->cycle->log_use_stderr = 1;
+ log->file = ngx_conf_open_file(cf->cycle, &name);
+ if (log->file == NULL) {
+ return NGX_CONF_ERROR;
+ }
}
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
@@ -1282,7 +1289,17 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(log, sizeof(ngx_http_log_t));
- if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) {
+ if (ngx_strcmp(value[1].data, "stderr") == 0) {
+ ngx_str_null(&name);
+ cf->cycle->log_use_stderr = 1;
+
+ log->file = ngx_conf_open_file(cf->cycle, &name);
+ if (log->file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ goto process_formats;
+ } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) {
peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t));
if (peer == NULL) {
diff --git a/src/stream/ngx_stream_log_module.c b/src/stream/ngx_stream_log_module.c
index 0ff7f42..14ddc74 100644
--- a/src/stream/ngx_stream_log_module.c
+++ b/src/stream/ngx_stream_log_module.c
@@ -1014,7 +1014,17 @@ ngx_stream_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(log, sizeof(ngx_stream_log_t));
- if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) {
+ if (ngx_strcmp(value[1].data, "stderr") == 0) {
+ ngx_str_null(&name);
+ cf->cycle->log_use_stderr = 1;
+
+ log->file = ngx_conf_open_file(cf->cycle, &name);
+ if (log->file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ goto process_formats;
+ } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) {
peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t));
if (peer == NULL) {
--
2.25.0