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