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 Jayesh Vora <ja...@gmail.com> on 2004/12/08 11:57:45 UTC

How can I prevent a log file from getting created?

Hi,

In my code, I call PropertyConfigurator.configure() method to
configure my log files. This creates the log files at the specified
location if they are not present.

If before this, I know (at runtime) that I am not going to use a
particular log file and instead I want to use a new log file (I can do
this with the help of code below), how can I prevent "creation" of the
original log file? Please note that I can't change log4j configuration
file for this, because at runtime I decide to take a different course.

code fragment:
      FileAppender appender = (FileAppender) logger.getAppender("SomeFile");

      Layout lo = appender.getLayout();

      appender.close();
      logger.removeAppender(appender);

      FileAppender app2 = null;

      try {
          app2 = new FileAppender(lo, "D:/log/new_file.log", true);
      } catch (Exception e) {
          e.printStackTrace();
      }

      logger.addAppender(app2);

Thanks,
Jayesh

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