You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "i314523@addcom.de" <i3...@addcom.de> on 2007/04/26 16:00:55 UTC

Multiple entries for one message in Logfile

Hi all,
I'm new to log4J and think that I have a configuration problem. But 
let me explain a little. I'm using Weblogic server 8.1. In my EAR I put 
a central Debug class, which collects all Debug messages and prints it 
to a logfile. I don't understand why I have the Logger class in each of 
my files. This is what I've done:

public class Debug {
    private static Logger logger = Logger.getLogger("com.tsystems.
spring.lion");

    public static void init() throws IOException {
//   the following is only for testing purposes, I don't have a config 
file yet
    try {
            Layout layout = new PatternLayout("%d [%t] %p - %m%n");
            FileAppender appender= new FileAppender(layout, logDir + 
"/" + baseName + ".log");
            logger.addAppender(appender);
     } catch (java.io.IOException e) {}
}

    public static void log(String message) {
        logger.debug(message);
   }
}

public class Foo {
... some code ...
Debug.log("This is a debug message");
}

The proble is that the log message appears *multiple* (3 to 4 times) 
in my logfile. Same timestamp, same message. Now my question: What have 
I to configure that the output only appears once? Where should I place 
the initialization file (config file) for log4j that it could be found?

TIA,
Ralf.


Jetzt neu: Der Routenplaner von Tiscali
http://www.tiscali.de/trav/routenplaner.html


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Multiple entries for one message in Logfile

Posted by Jacob Kjome <ho...@visi.com>.
You're either running into an additivity issue or a reconfiguration issue.  I
would guess it's the latter in this case.  I would guess that init is being
called multiple times.  Each time, a new appender is added pointing to the same
log file.  Each appender writes to the log file.  If you have 4 of them, you'll
get 4 entries for every call to your log() method.

I suggest you don't perform configuration in your class, or at least perform it
in a static block so it only ever gets executed once.  The best thing to do is
move this to an external log4j.properties or log4j.xml file and let Log4j load
it up automatically at server startup.

Jake

Quoting "i314523@addcom.de" <i3...@addcom.de>:

> Hi all,
> I'm new to log4J and think that I have a configuration problem. But
> let me explain a little. I'm using Weblogic server 8.1. In my EAR I put
> a central Debug class, which collects all Debug messages and prints it
> to a logfile. I don't understand why I have the Logger class in each of
> my files. This is what I've done:
>
> public class Debug {
>     private static Logger logger = Logger.getLogger("com.tsystems.
> spring.lion");
>
>     public static void init() throws IOException {
> //   the following is only for testing purposes, I don't have a config
> file yet
>     try {
>             Layout layout = new PatternLayout("%d [%t] %p - %m%n");
>             FileAppender appender= new FileAppender(layout, logDir +
> "/" + baseName + ".log");
>             logger.addAppender(appender);
>      } catch (java.io.IOException e) {}
> }
>
>     public static void log(String message) {
>         logger.debug(message);
>    }
> }
>
> public class Foo {
> ... some code ...
> Debug.log("This is a debug message");
> }
>
> The proble is that the log message appears *multiple* (3 to 4 times)
> in my logfile. Same timestamp, same message. Now my question: What have
> I to configure that the output only appears once? Where should I place
> the initialization file (config file) for log4j that it could be found?
>
> TIA,
> Ralf.
>
>
> Jetzt neu: Der Routenplaner von Tiscali
> http://www.tiscali.de/trav/routenplaner.html
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Multiple entries for one message in Logfile

Posted by Curt Arnold <ca...@apache.org>.
On Apr 26, 2007, at 9:00 AM, i314523@addcom.de wrote:

> Hi all,
> I'm new to log4J and think that I have a configuration problem. But
> let me explain a little. I'm using Weblogic server 8.1. In my EAR I  
> put
> a central Debug class, which collects all Debug messages and prints it
> to a logfile. I don't understand why I have the Logger class in  
> each of
> my files. This is what I've done:
>
> public class Debug {
>     private static Logger logger = Logger.getLogger("com.tsystems.
> spring.lion");
>
>     public static void init() throws IOException {
> //   the following is only for testing purposes, I don't have a config
> file yet
>     try {
>             Layout layout = new PatternLayout("%d [%t] %p - %m%n");
>             FileAppender appender= new FileAppender(layout, logDir +
> "/" + baseName + ".log");
>             logger.addAppender(appender);
>      } catch (java.io.IOException e) {}
> }
>
>     public static void log(String message) {
>         logger.debug(message);
>    }
> }
>
> public class Foo {
> ... some code ...
> Debug.log("This is a debug message");
> }
>
> The proble is that the log message appears *multiple* (3 to 4 times)
> in my logfile. Same timestamp, same message. Now my question: What  
> have
> I to configure that the output only appears once? Where should I place
> the initialization file (config file) for log4j that it could be  
> found?
>
> TIA,
> Ralf.
>
>
> Jetzt neu: Der Routenplaner von Tiscali
> http://www.tiscali.de/trav/routenplaner.html
>
>


The most obvious possibility is that you are calling Debug.init() 3  
or 4 times.  Each time would create a new file appender and each  
would attempt to write the same log message to the same file.




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org