]> granicus.if.org Git - php/commitdiff
Move the logging mechanism to SAPI
authorZeev Suraski <zeev@php.net>
Thu, 10 Feb 2000 15:55:10 +0000 (15:55 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 10 Feb 2000 15:55:10 +0000 (15:55 +0000)
main/SAPI.h
main/main.c
sapi/aolserver/aolserver.c
sapi/apache/mod_php4.c
sapi/cgi/cgi_main.c
sapi/isapi/php4isapi.c
sapi/phttpd/phttpd.c
sapi/roxen/roxen.c
sapi/servlet/servlet.c
sapi/thttpd/thttpd.c

index 7500b3ee201245b9f3e206dfad297e1ed38bebc6..60fc8efc6d45b548dd0db667f3f42735e4bd5bef 100644 (file)
@@ -148,6 +148,7 @@ struct _sapi_module_struct {
        char *(*read_cookies)(SLS_D);
 
        void (*register_server_variables)(zval *track_vars_array ELS_DC SLS_DC PLS_DC);
+       void (*log_message)(char *message);
 
        void (*default_post_reader)(char *content_type_dup SLS_DC);
 };
index e8706ac29f79071fcc47736db0a004d4846bb636..3a1dc2e8e26673d871e01f08e3302fc96751afce 100644 (file)
@@ -255,9 +255,6 @@ void php_log_err(char *log_message)
        struct tm tmbuf;
        time_t error_time;
        PLS_FETCH();
-#if APACHE
-       SLS_FETCH();
-#endif
 
        /* Try to use the specified logging location. */
        if (PG(error_log) != NULL) {
@@ -265,42 +262,25 @@ void php_log_err(char *log_message)
                if (!strcmp(PG(error_log), "syslog")) {
                        syslog(LOG_NOTICE, log_message);
                        return;
-               } else {
-#endif
-                       log_file = fopen(PG(error_log), "a");
-                       if (log_file != NULL) {
-                               time(&error_time);
-                               strftime(error_time_str, 128, "%d-%b-%Y %H:%M:%S", localtime_r(&error_time, &tmbuf)); 
-                               fprintf(log_file, "[%s] ", error_time_str);
-                               fprintf(log_file, log_message);
-                               fprintf(log_file, "\n");
-                               fclose(log_file);
-                               return;
-                       }
-#if HAVE_SYSLOG_H
                }
 #endif
+               log_file = fopen(PG(error_log), "a");
+               if (log_file != NULL) {
+                       time(&error_time);
+                       strftime(error_time_str, 128, "%d-%b-%Y %H:%M:%S", localtime_r(&error_time, &tmbuf)); 
+                       fprintf(log_file, "[%s] ", error_time_str);
+                       fprintf(log_file, log_message);
+                       fprintf(log_file, "\n");
+                       fclose(log_file);
+                       return;
+               }
        }
-       /* Otherwise fall back to the default logging location. */
-#if APACHE
-       if (SG(server_context)) {
-#if MODULE_MAGIC_NUMBER >= 19970831
-               aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, log_message);
-#else
-               log_error(log_message, ((requset_rec *) SG(server_context))->server);
-#endif
-       } else {
-               fprintf(stderr, log_message);
-               fprintf(stderr, "\n");
-       }
-#endif                                                 /*APACHE */
 
-#if CGI_BINARY
-       if (php_header()) {
-               fprintf(stderr, log_message);
-               fprintf(stderr, "\n");
+       /* Otherwise fall back to the default logging location, if we have one */
+
+       if (sapi_module.log_message) {
+               sapi_module.log_message(log_message);
        }
-#endif
 }
 
 
index 2b588dc1f213fbad338b7bd3dd2e667646e5cee1..eeb3b1c80772cdcc2e16ccd1e17655454615eaa7 100644 (file)
@@ -288,6 +288,7 @@ php_ns_startup(sapi_module_struct *sapi_module)
        }
 }
 
+
 /* this structure is static (as in "it does not change") */
 
 static sapi_module_struct sapi_module = {
@@ -309,6 +310,7 @@ static sapi_module_struct sapi_module = {
        php_ns_sapi_read_cookies,                               /* read Cookies */
 
        NULL,                                                                   /* register server variables */
+       NULL,                                                                   /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index 74bba3467e932d7ad9eb199346e55c1c84ff8002..c7ac6cd8c30eb549701e8412ef0aa2b02860b7e1 100644 (file)
@@ -267,6 +267,23 @@ php_apache_startup(sapi_module_struct *sapi_module)
 }
 
 
+static void php_apache_log_message(char *message)
+{
+       SLS_FETCH();
+
+       if (SG(server_context)) {
+#if MODULE_MAGIC_NUMBER >= 19970831
+               aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, message);
+#else
+               log_error(message, ((requset_rec *) SG(server_context))->server);
+#endif
+       } else {
+               fprintf(stderr, message);
+               fprintf(stderr, "\n");
+       }
+}
+
+
 static sapi_module_struct sapi_module = {
        "Apache",                                               /* name */
                                                                        
@@ -287,6 +304,7 @@ static sapi_module_struct sapi_module = {
        sapi_apache_read_cookies,               /* read Cookies */
 
        sapi_apache_register_server_variables,          /* register server variables */
+       php_apache_log_message,                 /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index d942d264a89bf896b621304ada0db31a3d95242e..b0634c21926e5839afb991c2a3a93456fb41a64e 100644 (file)
@@ -159,6 +159,15 @@ static void sapi_cgi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS
 }
 
 
+static void sapi_cgi_log_message(char *message)
+{
+       if (php_header()) {
+               fprintf(stderr, message);
+               fprintf(stderr, "\n");
+       }
+}
+
+
 static sapi_module_struct sapi_module = {
        "CGI",                                                  /* name */
                                                                        
@@ -178,6 +187,7 @@ static sapi_module_struct sapi_module = {
        sapi_cgi_read_cookies,                  /* read Cookies */
 
        sapi_cgi_register_variables,    /* register server variables */
+       sapi_cgi_log_message,                   /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index 6db380b675cc6302336559caad5474d9b55c8c2a..83e8c04ad2bb41484c258aac781a98ed7456220c 100644 (file)
@@ -358,6 +358,7 @@ static sapi_module_struct sapi_module = {
        sapi_isapi_read_cookies,                /* read Cookies */
 
        sapi_isapi_register_server_variables,   /* register server variables */
+       NULL,                                                                   /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index 57d14e9639516eeb6d83604cf5b51aafbeaade17..a766816899330d551857c9fe7146727c56f77edc 100644 (file)
@@ -180,6 +180,7 @@ static sapi_module_struct sapi_module = {
     php_phttpd_sapi_read_cookies,           /* read Cookies */
  
        NULL,                                                                   /* register server variables */
+       NULL,                                                                   /* Log message */
 
     STANDARD_SAPI_MODULE_PROPERTIES
 };
index 9fb78b5a93194449d2139f2ea373b9d168f5561a..7c797667e6fe674979aa8a935d562ff571e4f685 100644 (file)
@@ -534,6 +534,7 @@ static sapi_module_struct sapi_module = {
   php_roxen_sapi_read_cookies,                         /* read Cookies */
 
   NULL,                                                                                /* register server variables */
+  NULL,                                                                                /* Log message */
 
 
   STANDARD_SAPI_MODULE_PROPERTIES
index 36e8c81360acd5d4332e373c8987b7ae5a1b4152..463baeaecbc5df1cbddd34267aaa904a2448cc1f 100644 (file)
@@ -236,6 +236,7 @@ static sapi_module_struct sapi_module = {
        sapi_servlet_read_cookies,              /* read Cookies */
 
        NULL,                                                   /* register server variables */
+       NULL,                                                   /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index 81726c2205937562bb9b7e682e362a9159bcf0a1..363347512904c77ad97aa5cc8ee40f6d7db72358 100644 (file)
@@ -119,6 +119,7 @@ static sapi_module_struct sapi_module = {
        sapi_thttpd_read_cookies,
 
        NULL,                                                   /* register server variables */
+       NULL,                                                   /* Log message */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };