]> git.kaiwu.me - nginx.git/commitdiff
Syslog: added "nohostname" option.
authorVladimir Homutov <vl@nginx.com>
Mon, 26 Oct 2015 16:06:42 +0000 (19:06 +0300)
committerVladimir Homutov <vl@nginx.com>
Mon, 26 Oct 2015 16:06:42 +0000 (19:06 +0300)
The option disables sending hostname in the syslog message header.  This is
useful with syslog daemons that do not expect it (tickets #677 and #783).

src/core/ngx_syslog.c
src/core/ngx_syslog.h

index d4e79f67d9f319c4409751459e1febba57343e75..08f4c04831d954138167790897b072b309e85107 100644 (file)
@@ -194,6 +194,9 @@ ngx_syslog_parse_args(ngx_conf_t *cf, ngx_syslog_peer_t *peer)
             peer->tag.data = p + 4;
             peer->tag.len = len - 4;
 
+        } else if (len == 10 && ngx_strncmp(p, "nohostname", 10) == 0) {
+            peer->nohostname = 1;
+
         } else {
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "unknown syslog parameter \"%s\"", p);
@@ -220,6 +223,11 @@ ngx_syslog_add_header(ngx_syslog_peer_t *peer, u_char *buf)
 
     pri = peer->facility * 8 + peer->severity;
 
+    if (peer->nohostname) {
+        return ngx_sprintf(buf, "<%ui>%V %V: ", pri, &ngx_cached_syslog_time,
+                           &peer->tag);
+    }
+
     return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri, &ngx_cached_syslog_time,
                        &ngx_cycle->hostname, &peer->tag);
 }
index a9150516f6b70ef0bc350b76d77e6932be0421e7..cc4c842c7522729829be7e52120a12e75c87fd4f 100644 (file)
@@ -16,7 +16,8 @@ typedef struct {
 
     ngx_addr_t        server;
     ngx_connection_t  conn;
-    ngx_uint_t        busy;  /* unsigned busy:1; */
+    unsigned          busy:1;
+    unsigned          nohostname:1;
 } ngx_syslog_peer_t;