You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Glenn Nielsen <gl...@voyager.apg.more.net> on 2002/02/20 12:18:13 UTC

Re: [PATCH] log output can get messed up with org.apache.catalina.logger.FileLogger

Kevin Seguin wrote:
> 
> if a lot of log messages are being written to a file by a lot of threads using org.apache.catalina.logger.FileLogger, the output can get messed up so that you get things like this:
> 
> [timestamp-1] [timestamp-2] [message-1]
> [message-2]
> 
> instead of this:
> 
> [timestamp-1] [message-1]
> [timestamp-2] [message-2]
> 
> i ran into this while trying to debug bug 5735, which requires a decent load (i.e. lots of threads).
> 
> attached is a patch with one possible solution  - i could commit this, but i generally don't commit on tomcat4, so i'd like some +1's before committing :)

Index: catalina/src/share/org/apache/catalina/logger/FileLogger.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/logger/FileLogger.java,v
retrieving revision 1.3.2.1
diff -u -b -r1.3.2.1 FileLogger.java
--- catalina/src/share/org/apache/catalina/logger/FileLogger.java       25 Oct 2001
20:07:44 -0000      1.3.2.1
+++ catalina/src/share/org/apache/catalina/logger/FileLogger.java       19 Feb 2002
19:44:33 -0000
@@ -289,13 +289,14 @@
 
         // Log this message, timestamped if necessary
         if (writer != null) {
+            synchronized (writer) {
             if (timestamp) {
                 writer.print(tsString);
                 writer.print(" ");
             }
             writer.println(msg);
         }
-
+        }
     }

Another way to fix this would be to use String concatenation.  The question
is, which is more expensive, the synchronization or the String concatenation?

This is how the code would be with String concatenation:

         // Log this message, timestamped if necessary
         if (writer != null) {
             if (timestamp) {
                 writer.println(tsString + " " + msg);
             } else {
                writer.println(msg);
             }
         }

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>