Starbax
Starbax

Reputation: 1035

log4j logs to my logfile AND catalina.out

my logger logs to my logfile and the catalina.out i don't know how to solve it, I don't want the logger to log to both.

here is my code:

private static final Logger logger = Logger.getLogger("FA");

[...]

if(logger.getAppender("walletServicesAppender")==null)
    {
        try
        {

      appenderLayout = new PatternLayout();
      appenderLayout.setConversionPattern("%d %p - %m%n");
      appender = new FileAppender(appenderLayout,"/home/marcel/try/log_file_name.txt");
      appender.setName("walletServicesAppender");
      logger.addAppender(appender);
      logger.setLevel(org.apache.log4j.Level.ALL);
    }
    catch (IOException ex)
    {
      logger.error("Cannot access log file: "+ex.getLocalizedMessage());
    }    
    catch(Exception ex)
    {
      logger.error("Unknown exception: "+ex.getLocalizedMessage());
    }
    }
logger.info("INFO MESSAGE!");

[...]

This always makes a double log to log_file_name.txt AND catalina.out

Thanks for help.

EDIT:

logger.setAdditivity(false);

solved my problem

Thanks for your help!

Upvotes: 1

Views: 5056

Answers (2)

agnul
agnul

Reputation: 13048

You probably have a ConsoleAppender in your log4j configuration, check for a line like

log4j.appender.SOME_APPENDER_NAME=org.apache.log4j.ConsoleAppender

in your log4j.properties file, or something equivalent if your are using XML configuration.

Upvotes: 3

Ian Phillips
Ian Phillips

Reputation: 173

It sounds like there is another appender attached to your logger, you could try adding this code to find out which appender it is:

for (Enumeration e = logger.getAllAppenders(); e.hasMoreElements(); ) {
    System.out.println("A:" + ((Appender) e.nextElement()).getName());
}

then look through your source and/or config files to see where it's being set.

Upvotes: 1

Related Questions