I have a proposal for a slight enhancement concerning the log format of
mod_jk. As suggested by Henri Gomez, I sent the proposal to the
tomcat-dev list.

1) Include the log level of a message in the log line. That should be
easy and is very helpful to find relevant messages. It is a pretty
standard feature.

2) Include the PID of the logging process in the log file. That helps a
lot, because one can also log the PID in Apaches access log. So it is
easier to relate access log lines and mod_jk log lines to each other.
Also it helps to unmangle, if log lines from several parallel requests
are mixed. Of course this argumentation mainly is for apache 1.3, but
most people use mod_jk for it.

Both enhancements can be done in jk/native/common/jk_util.c.

I attach a small patch, which I also include at the end of the message.

Since I'm not an experienced C developer please
check. I borrowed a define for Netware for getpid() from Apache's code.
Not sure If it will work for Netware, or if configure needs to be
enhanced, if we use getpid(). It build well on Solaris and it is
done in the same way inside core apache.

The patch is in "diff -Nru"-format and is based on
jk/native/common/jk_util.c revision 1.28. I hope this is still up to date.

Thank's for considering.

Rainer Jung

--- jk_util.c   Tue Jul 13 15:58:10 2004
+++ jk_util.c.new       Thu Aug 12 18:11:50 2004
@@ -85,6 +85,14 @@

  const char * jk_log_fmt = JK_TIME_FORMAT;

+int log_level_max = 3;
+static const char *log_levels[] = {
+    JK_LOG_DEBUG_VERB,
+    JK_LOG_INFO_VERB,
+    JK_LOG_ERROR_VERB,
+    JK_LOG_EMERG_VERB
+};
+
  static void set_time_str(char * str, int len)
  {
      time_t      t = time(NULL);
@@ -250,19 +258,32 @@
              f++;
          }

+        const char *log_level;
+        if ( level >=0 && level <= log_level_max ) {
+            log_level=log_levels[level];
+        } else {
+            log_level="unknown";
+        }
+
+#ifdef NETWARE
+#define getpid() ((pid_t)GetThreadGroupID())
+#endif
+
  #ifdef USE_SPRINTF /* until we get a snprintf function */
  #ifdef NETWARE
          buf = (char *) malloc(HUGE_BUFFER_SIZE);
          if (NULL == buf)
             return -1;
  #endif
-    set_time_str(buf, HUGE_BUFFER_SIZE);
-    used = strlen(buf);
+        set_time_str(buf, HUGE_BUFFER_SIZE);
+        used = strlen(buf);
+        used += sprintf(&buf[used], "[%s] [%ld]", log_level,
(long)getpid());
          if(line)
              used += sprintf(&buf[used], " [%s (%d)]: ", f, line);
  #else
-    set_time_str(buf, HUGE_BUFFER_SIZE);
-    used = strlen(buf);
+        set_time_str(buf, HUGE_BUFFER_SIZE);
+        used = strlen(buf);
+        used += snprintf(&buf[used], HUGE_BUFFER_SIZE, "[%s] [%ld]",
log_level, (long)getpid());
          if(line)
              used += snprintf(&buf[used], HUGE_BUFFER_SIZE, " [%s
(%d)]: ", f, line);
  #endif




--- jk_util.c   Tue Jul 13 15:58:10 2004
+++ jk_util.c.new       Thu Aug 12 18:11:50 2004
@@ -85,6 +85,14 @@
 
 const char * jk_log_fmt = JK_TIME_FORMAT;
 
+int log_level_max = 3;
+static const char *log_levels[] = {
+    JK_LOG_DEBUG_VERB,
+    JK_LOG_INFO_VERB,
+    JK_LOG_ERROR_VERB,
+    JK_LOG_EMERG_VERB
+};
+
 static void set_time_str(char * str, int len)
 {
     time_t      t = time(NULL);
@@ -250,19 +258,32 @@
             f++;
         }
 
+        const char *log_level;
+        if ( level >=0 && level <= log_level_max ) {
+            log_level=log_levels[level];
+        } else {
+            log_level="unknown";
+        }
+
+#ifdef NETWARE
+#define getpid() ((pid_t)GetThreadGroupID())
+#endif
+
 #ifdef USE_SPRINTF /* until we get a snprintf function */
 #ifdef NETWARE
         buf = (char *) malloc(HUGE_BUFFER_SIZE);
         if (NULL == buf)
            return -1;
 #endif
-    set_time_str(buf, HUGE_BUFFER_SIZE);
-    used = strlen(buf);
+        set_time_str(buf, HUGE_BUFFER_SIZE);
+        used = strlen(buf);
+        used += sprintf(&buf[used], "[%s] [%ld]", log_level, (long)getpid());
         if(line)
             used += sprintf(&buf[used], " [%s (%d)]: ", f, line);
 #else 
-    set_time_str(buf, HUGE_BUFFER_SIZE);
-    used = strlen(buf);
+        set_time_str(buf, HUGE_BUFFER_SIZE);
+        used = strlen(buf);
+        used += snprintf(&buf[used], HUGE_BUFFER_SIZE, "[%s] [%ld]", log_level, 
(long)getpid());
         if(line)
             used += snprintf(&buf[used], HUGE_BUFFER_SIZE, " [%s (%d)]: ", f, line);  
      
 #endif


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to