Skip to content

Commit

Permalink
add syslog_set
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweibin committed May 4, 2011
1 parent 26b705a commit 28b0fee
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions new_syslog_0.8.54.patch
@@ -1,21 +1,22 @@
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 357c6b2..4de4952 100644
index 357c6b2..53053da 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -84,6 +84,11 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
@@ -84,6 +84,12 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
cycle->pool = pool;
cycle->log = log;
cycle->new_log.log_level = NGX_LOG_ERR;
+#if (NGX_ENABLE_SYSLOG)
+ cycle->new_log.facility = SYSLOG_FACILITY;
+ cycle->new_log.facility = ERR_SYSLOG_PRIORITY;
+ cycle->new_log.syslog_on = 0;
+ cycle->new_log.syslog_set = 0;
+#endif
cycle->old_cycle = old_cycle;

cycle->conf_prefix.len = old_cycle->conf_prefix.len;
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index c0485c6..d1f3105 100644
index c0485c6..0e07b04 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -9,6 +9,15 @@
Expand Down Expand Up @@ -229,18 +230,20 @@ index c0485c6..d1f3105 100644

if (cf->cycle->new_log.file) {
return "is duplicate";
@@ -428,7 +564,42 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
@@ -428,7 +564,44 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

value = cf->args->elts;

+#if (NGX_ENABLE_SYSLOG)
+ if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
+ if (!cf->cycle->new_log.syslog_on) {
+ if (!cf->cycle->new_log.syslog_set) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "You must set the syslog directive and enable it first.");
+ return NGX_CONF_ERROR;
+ }
+
+ cf->cycle->new_log.syslog_on = 1;
+
+ if (value[1].data[sizeof("syslog") - 1] == ':') {
+ priority.len = value[1].len - sizeof("syslog");
+ priority.data = value[1].data + sizeof("syslog");
Expand Down Expand Up @@ -272,7 +275,7 @@ index c0485c6..d1f3105 100644
ngx_str_null(&name);

} else {
@@ -449,3 +620,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
@@ -449,3 +622,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

return ngx_log_set_levels(cf, &cf->cycle->new_log);
}
Expand All @@ -292,11 +295,11 @@ index c0485c6..d1f3105 100644
+
+ value = cf->args->elts;
+
+ if (cf->cycle->new_log.syslog_on) {
+ if (cf->cycle->new_log.syslog_set) {
+ return "is duplicate";
+ }
+
+ cf->cycle->new_log.syslog_on = 1;
+ cf->cycle->new_log.syslog_set = 1;
+
+ for (n = 0; ngx_syslog_facilities[n].name.len != 0; n++) {
+ if (ngx_strncmp(value[1].data, ngx_syslog_facilities[n].name.data,
Expand Down Expand Up @@ -330,14 +333,14 @@ index c0485c6..d1f3105 100644
+
+void log_exit(ngx_cycle_t *cycle)
+{
+ if (cycle->new_log.syslog_on) {
+ if (cycle->new_log.syslog_set) {
+ closelog();
+ }
+}
+#endif
+
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 1054836..a5982c0 100644
index 1054836..14288ee 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -11,6 +11,13 @@
Expand All @@ -354,7 +357,7 @@ index 1054836..a5982c0 100644

#define NGX_LOG_STDERR 0
#define NGX_LOG_EMERG 1
@@ -60,6 +67,12 @@ struct ngx_log_s {
@@ -60,6 +67,13 @@ struct ngx_log_s {
*/

char *action;
Expand All @@ -363,11 +366,12 @@ index 1054836..a5982c0 100644
+ ngx_int_t priority;
+ ngx_int_t facility;
+ unsigned syslog_on:1; /* unsigned :1 syslog_on */
+ unsigned syslog_set:1; /*unsigned :1 syslog_set */
+#endif
};


@@ -197,6 +210,10 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
@@ -197,6 +211,10 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,

ngx_log_t *ngx_log_init(u_char *prefix);
ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
Expand All @@ -379,7 +383,7 @@ index 1054836..a5982c0 100644
void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 5f356c3..51a6732 100644
index 5f356c3..191a4a5 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -8,6 +8,11 @@
Expand Down Expand Up @@ -468,7 +472,7 @@ index 5f356c3..51a6732 100644
}
+#if (NGX_ENABLE_SYSLOG)
+ else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
+ if (!cf->cycle->new_log.syslog_on) {
+ if (!cf->cycle->new_log.syslog_set) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "You must set the syslog directive and enable it first.");
+ return NGX_CONF_ERROR;
Expand Down

0 comments on commit 28b0fee

Please sign in to comment.