Changeset 913

Show
Ignore:
Timestamp:
09/11/07 13:23:15 (1 year ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r912 r913  
     12007-09-11  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     2 
     3        * cherokee/trace.h, cherokee/trace.c, cherokee/macros.h, 
     4        cherokee/Makefile.am, cherokee/util.c, cherokee/util.h, 
     5        cherokee/cherokee.h, cherokee/server.c, configure.in: Tracing 
     6        facility moved to an independent file. The code has been slightly 
     7        reworked in order to allow the modification of the modules been 
     8        traced dynamically. 
     9 
    1102007-09-07  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    211 
  • cherokee/trunk/cherokee/Makefile.am

    r912 r913  
    736736util.h \ 
    737737util.c \ 
     738trace.h \ 
     739trace.c \ 
    738740version.h \ 
    739741version.c \ 
  • cherokee/trunk/cherokee/cherokee.h

    r841 r913  
    4444#include <cherokee/resolv_cache.h> 
    4545#include <cherokee/post.h> 
     46#include <cherokee/trace.h> 
    4647 
    4748/* Server library 
  • cherokee/trunk/cherokee/macros.h

    r906 r913  
    311311/* Tracing facility 
    312312 */ 
     313#define TRACE_ENV "CHEROKEE_TRACE" 
     314 
    313315#ifdef TRACE_ENABLED 
    314 # define TRACE_ENV "CHEROKEE_TRACE" 
    315  
    316316# ifdef __GNUC__ 
    317 #  define TRACE(fmt,arg...) cherokee_trace (fmt, __FILE__, __LINE__, __cherokee_func__, ##arg) 
    318 # else 
    319 #  define TRACE(fmt,...) cherokee_trace (fmt, __FILE__, __LINE__, __cherokee_func__, __VA_ARGS__) 
     317#  define TRACE(fmt,arg...) cherokee_trace_do_trace (fmt, __FILE__, __LINE__, __cherokee_func__, ##arg) 
     318# else 
     319#  define TRACE(fmt,...) cherokee_trace_do_trace (fmt, __FILE__, __LINE__, __cherokee_func__, __VA_ARGS__) 
    320320# endif 
    321321#else 
  • cherokee/trunk/cherokee/server.c

    r906 r913  
    100100        ret_t ret; 
    101101        CHEROKEE_NEW_STRUCT(n, server); 
     102 
     103        cherokee_trace_init (); 
    102104         
    103105        /* Thread list 
  • cherokee/trunk/cherokee/util.c

    r900 r913  
    897897 
    898898 
    899  
    900 #ifdef TRACE_ENABLED 
    901  
    902 void 
    903 cherokee_trace (const char *entry, const char *file, int line, const char *func, const char *fmt, ...) 
    904 { 
    905         static char        *env         = NULL; 
    906         static cuint_t      env_set     = 0; 
    907         static cuint_t      use_syslog  = 0; 
    908         cherokee_boolean_t  do_log      = false; 
    909         cherokee_buffer_t   entries     = CHEROKEE_BUF_INIT; 
    910         cherokee_buffer_t   output      = CHEROKEE_BUF_INIT; 
    911         char               *lentry; 
    912         char               *lentry_end; 
    913         va_list             args; 
    914         char               *p; 
    915          
    916         /* Read the environment variable in the first call 
    917          */ 
    918         if (env_set == 0) { 
    919                 env     = getenv(TRACE_ENV); 
    920                 env_set = 1; 
    921  
    922                 if (env != NULL)  
    923                         use_syslog = (strstr (env, "syslog") != NULL); 
    924         } 
    925  
    926         /* Return quickly if there isn't anything to do 
    927          */ 
    928         if (env == NULL) { 
    929                 return; 
    930         } 
    931         
    932         cherokee_buffer_add (&entries, entry, strlen(entry)); 
    933  
    934         for (lentry = entries.buf;;) { 
    935                 lentry_end = strchr (lentry, ','); 
    936                 if (lentry_end) *lentry_end = '\0'; 
    937  
    938                 /* Check for 'all' 
    939                  */ 
    940                 p = strstr (env, "all"); 
    941                 if (p) do_log = true; 
    942  
    943                 /* Check the type 
    944                  */ 
    945                 p = strstr (env, lentry); 
    946                 if (p) { 
    947                         char *tmp = p + strlen(lentry); 
    948                         if ((*tmp == '\0') || (*tmp == ',') || (*tmp == ' ')) 
    949                                 do_log = true; 
    950                 } 
    951  
    952                 if (lentry_end == NULL) 
    953                         break; 
    954  
    955                 lentry = lentry_end + 1; 
    956         } 
    957  
    958         if (! do_log) goto out; 
    959  
    960         /* Print the trace 
    961          */ 
    962         cherokee_buffer_add_va (&output, "%18s:%04d (%30s): ", file, line, func); 
    963  
    964         va_start (args, fmt); 
    965         cherokee_buffer_add_va_list (&output, (char *)fmt, args); 
    966         va_end (args); 
    967  
    968         if (use_syslog) { 
    969                 syslog (LOG_DEBUG, "%s", output.buf); 
    970         } else { 
    971 #ifdef HAVE_FLOCKFILE 
    972                 flockfile (stdout); 
    973 #endif 
    974                 fprintf (stdout, "%s", output.buf); 
    975 #ifdef HAVE_FUNLOCKFILE 
    976                 funlockfile (stdout); 
    977 #endif 
    978         } 
    979  
    980 out: 
    981         cherokee_buffer_mrproper (&output); 
    982         cherokee_buffer_mrproper (&entries); 
    983 } 
    984  
    985 #endif 
    986  
    987  
    988  
    989899ret_t  
    990900cherokee_short_path (cherokee_buffer_t *path) 
  • cherokee/trunk/cherokee/util.h

    r862 r913  
    3232#include <cherokee/common.h> 
    3333#include <cherokee/avl.h> 
     34#include <cherokee/trace.h> 
    3435 
    3536#ifdef HAVE_NETINET_IN_H 
  • cherokee/trunk/configure.in

    r903 r913  
    131131AC_DEFINE_UNQUOTED(OS_TYPE, "${os_string}", [OS type]) 
    132132 
     133AM_CONDITIONAL(PLATFORM_WIN32, test x"$os_string" = "xWin32") 
     134 
     135dnl 
     136dnl Tracing 
     137dnl 
    133138AC_ARG_ENABLE(trace, AC_HELP_STRING([--enable-trace], [Enable trace facility]),  
    134139   [enable_trace="$enableval" 
     
    136141   ], [enable_trace="no"]) 
    137142 
     143 
    138144dnl 
    139145dnl Dynamic library loading library 
     
    142148AC_DEFINE_UNQUOTED(SO_SUFFIX, "${so_suffix}", [Dynamic loading libraries extension]) 
    143149AC_DEFINE_UNQUOTED(MOD_SUFFIX, "${mod_suffix}", [Dynamic modules extension]) 
    144  
    145 dnl 
    146 dnl Platforms 
    147 dnl 
    148 AM_CONDITIONAL(PLATFORM_WIN32, test x"$os_string" = "xWin32") 
    149150 
    150151dnl