Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


   


   


   















      :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: piped logging from Nginx to MySQL



On Wed, 2009-12-16 at 12:08 +0100, Gerasimenko Konstantin wrote:

> da bilobi ochen ne ploxo ... 
> 
> Spasibo !!!
> 

     ,   0.8.  .
  --with-syslog


-- 
Vasiliy G Tolstov <v.tolstov@xxxxxxxxx>
Selfip.Ru
diff -ruabB nginx-0.7.38.orig/auto/make nginx-0.7.38/auto/make
--- nginx-0.7.38.orig/auto/make 2008-03-18 13:36:27.000000000 +0300
+++ nginx-0.7.38/auto/make      2009-03-04 09:51:37.000000000 +0300
@@ -13,6 +13,10 @@
 ngx_objs_dir=$NGX_OBJS$ngx_regex_dirsep
 ngx_use_pch=`echo $NGX_USE_PCH | sed -e "s/\//$ngx_regex_dirsep/g"`
 
+#SYSLOG
+if [[ "${USE_SYSLOG}" == "YES" ]]; then
+   CFLAGS="$CFLAGS -DUSE_SYSLOG"
+fi
 
 cat << END                                                     > $NGX_MAKEFILE
 
diff -ruabB nginx-0.7.38.orig/auto/options nginx-0.7.38/auto/options
--- nginx-0.7.38.orig/auto/options      2009-02-21 10:02:02.000000000 +0300
+++ nginx-0.7.38/auto/options   2009-03-04 09:51:37.000000000 +0300
@@ -108,6 +108,8 @@
 MD5_OPT=
 MD5_ASM=NO
 
+USE_SYSLOG=NO
+
 USE_SHA1=NO
 SHA1=NONE
 SHA1_OPT=
@@ -245,6 +247,8 @@
         --with-sha1-opt=*)               SHA1_OPT="$value"          ;;
         --with-sha1-asm)                 SHA1_ASM=YES               ;;
 
+       --with-syslog)                   USE_SYSLOG=YES             ;;
+       
         --with-zlib=*)                   ZLIB="$value"              ;;
         --with-zlib-opt=*)               ZLIB_OPT="$value"          ;;
         --with-zlib-asm=*)               ZLIB_ASM="$value"          ;;
@@ -368,6 +372,8 @@
   --with-sha1-opt=OPTIONS            set additional options for sha1 building
   --with-sha1-asm                    use sha1 assembler sources
 
+  --with-syslog                      use syslog instead of files to log 
messages
+
   --with-zlib=DIR                    set path to zlib library sources
   --with-zlib-opt=OPTIONS            set additional options for zlib building
   --with-zlib-asm=CPU                use zlib assembler sources optimized
diff -ruabB nginx-0.7.38.orig/auto/summary nginx-0.7.38/auto/summary
--- nginx-0.7.38.orig/auto/summary      2008-05-16 18:32:58.000000000 +0400
+++ nginx-0.7.38/auto/summary   2009-03-04 09:51:37.000000000 +0300
@@ -64,6 +64,11 @@
     *)     echo "  + using sha1 library: $SHA1" ;;
 esac
 
+case $USE_SYSLOG in
+    YES)   echo "  + using syslog" ;;
+    *)     echo "  + syslog is not used" ;;
+esac
+
 case $ZLIB in
     YES)   echo "  + using system zlib library" ;;
     NONE)  echo "  + zlib library is not used" ;;
diff -ruabB nginx-0.7.38.orig/src/core/nginx.c nginx-0.7.38/src/core/nginx.c
--- nginx-0.7.38.orig/src/core/nginx.c  2008-11-11 19:17:45.000000000 +0300
+++ nginx-0.7.38/src/core/nginx.c       2009-03-04 09:51:37.000000000 +0300
@@ -8,6 +8,9 @@
 #include <ngx_core.h>
 #include <nginx.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
 static ngx_int_t ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv);
@@ -222,6 +225,11 @@
     ngx_ssl_init(log);
 #endif
 
+    /* SYSLOG SUPPORT */
+#ifdef USE_SYSLOG
+    openlog("nginx", LOG_ODELAY, LOG_DAEMON);
+#endif
+
     /* init_cycle->log is required for signal handlers and ngx_getopt() */
 
     ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
@@ -366,6 +374,10 @@
         ngx_single_process_cycle(cycle);
     }
 
+#ifdef USE_SYSLOG
+    closelog();
+#endif
+
     return 0;
 }
 
Only in nginx-0.7.38/src/core: nginx.c.orig
diff -ruabB nginx-0.7.38.orig/src/core/ngx_conf_file.c 
nginx-0.7.38/src/core/ngx_conf_file.c
--- nginx-0.7.38.orig/src/core/ngx_conf_file.c  2008-11-25 18:55:10.000000000 
+0300
+++ nginx-0.7.38/src/core/ngx_conf_file.c       2009-03-04 09:51:37.000000000 
+0300
@@ -851,6 +851,11 @@
     full.data = NULL;
 #endif
 
+#ifdef USE_SYSLOG
+if (name) {
+               name = NULL;
+}
+#endif
     if (name) {
         full = *name;
 
Only in nginx-0.7.38/src/core: ngx_conf_file.c.orig
diff -ruabB nginx-0.7.38.orig/src/core/ngx_log.c nginx-0.7.38/src/core/ngx_log.c
--- nginx-0.7.38.orig/src/core/ngx_log.c        2009-01-16 17:00:05.000000000 
+0300
+++ nginx-0.7.38/src/core/ngx_log.c     2009-03-04 09:51:37.000000000 +0300
@@ -7,6 +7,9 @@
 #include <ngx_config.h>
 #include <ngx_core.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
@@ -80,11 +83,11 @@
     va_list  args;
 #endif
     u_char   errstr[NGX_MAX_ERROR_STR], *p, *last;
-
+#ifndef USE_SYSLOG
     if (log->file->fd == NGX_INVALID_FILE) {
         return;
     }
-
+#endif
     last = errstr + NGX_MAX_ERROR_STR;
 
     ngx_memcpy(errstr, ngx_cached_err_log_time.data,
@@ -150,7 +153,22 @@
 
     ngx_linefeed(p);
 
+#ifdef USE_SYSLOG
+    /* allocate a string which can hold the error message */
+    char *syslogstr;
+
+    if ((syslogstr = calloc((p - errstr + 1), sizeof(char))) != NULL)
+    {
+        strncpy(syslogstr, errstr, p - errstr);
+
+       /* write to syslog */
+        syslog(LOG_CRIT, "%s", syslogstr);
+
+        free(syslogstr);
+    }
+#else
     (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
+#endif
 }
 
 
@@ -233,7 +251,7 @@
 {
     ngx_log_t  *log;
     ngx_str_t  *value, *name;
-
+#ifndef USE_SYSLOG
     if (args) {
         value = args->elts;
         name = &value[1];
@@ -237,10 +255,12 @@
     if (args) {
         value = args->elts;
         name = &value[1];
-
     } else {
+#endif
         name = NULL;
+#ifndef USE_SYSLOG
     }
+#endif
 
     log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
     if (log == NULL) {
@@ -320,6 +340,10 @@
 
     value = cf->args->elts;
 
+#ifdef USE_SYSLOG
+    value[1].data = "stderr";
+#endif
+
     if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
         cf->cycle->new_log->file->fd = ngx_stderr.fd;
         cf->cycle->new_log->file->name.len = 0;
diff -ruabB nginx-0.7.38.orig/src/http/modules/ngx_http_log_module.c 
nginx-0.7.38/src/http/modules/ngx_http_log_module.c
--- nginx-0.7.38.orig/src/http/modules/ngx_http_log_module.c    2008-10-16 
17:31:00.000000000 +0400
+++ nginx-0.7.38/src/http/modules/ngx_http_log_module.c 2009-03-04 
09:51:37.000000000 +0300
@@ -8,6 +8,9 @@
 #include <ngx_core.h>
 #include <ngx_http.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 typedef struct ngx_http_log_op_s  ngx_http_log_op_t;
 
@@ -310,6 +313,20 @@
 ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
     size_t len)
 {
+#ifdef USE_SYSLOG
+    /* allocate a string which can hold the error message */
+    char *syslogstr;
+
+    if ((syslogstr = calloc((len + 1), sizeof(char))) != NULL)
+    {
+        strncpy(syslogstr, buf, len);
+
+        /* write to syslog */
+        syslog(LOG_NOTICE, "%s", syslogstr);
+
+        free(syslogstr);
+    }
+#else
     u_char     *name;
     time_t      now;
     ssize_t     n;
@@ -354,6 +371,7 @@
 
         log->error_log_time = now;
     }
+#endif
 }
 
 
@@ -798,7 +816,11 @@
         return NGX_CONF_ERROR;
     }
 
+#ifdef USE_SYLOG
+    log->file = ngx_conf_open_file(cf->cycle, NULL);
+#else
     log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
+#endif
     if (log->file == NULL) {
         return NGX_CONF_ERROR;
     }
@@ -857,7 +879,11 @@
     n = ngx_http_script_variables_count(&value[1]);
 
     if (n == 0) {
+    #ifdef USE_SYSLOG
+        log->file = ngx_conf_open_file(cf->cycle, NULL);
+    #else
         log->file = ngx_conf_open_file(cf->cycle, &value[1]);
+    #endif
         if (log->file == NULL) {
             return NGX_CONF_ERROR;
         }
_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://nginx.org/mailman/listinfo/nginx-ru


 




Copyright © Lexa Software, 1996-2009.