0

I am working in a Linux server which comes with tomcat preinstalled(version 6) and we do not have admin access. I am trying to change the log file location(catalina.out), but it is not working.

I updated the tomcat6.conf file by adding the following

CATALINA_BASE="ORIG_LOC_FOLDER"
CATALINA_HOME="ORIG_LOC_FOLDER"
CATALINA_OUT="XXXX/catalina.out"

I restarted tomcat, but it still writes the logs to the old file in the old location. I could not change in the catalina.sh as I cannot find that file. Is there anything else I need to do?

Thanks.

user115391
  • 185
  • 1
  • 8
  • 22

1 Answers1

0

The setting of catalina.out can be found in $CATALINA_BASE/conf/logging.properties.

1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.

After copy and modify this file, you can override Tomcat's logging config file via this environment variable.

LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"

Update in 6/25

Another solution is changing java.util.logging configuration by program. Here is the sample code.

//import java.util.logging.*;
Logger logger = Logger.getLogger("");
Handler[] ha = logger.getHandlers();
for (int i = 0; i < ha.length; i++) {
    logger.removeHandler(ha[i]);
    ha[i].close();
}
Handler fh = new FileHandler("%t/out.log");
fh.setFormatter(new SimpleFormatter());
fh.setLevel (Level.FINE);
logger.addHandler (fh);
logger.setLevel (Level.FINE);
Beck Yang
  • 3,004
  • 2
  • 21
  • 26
  • Thanks, will check tonight and get back. – user115391 Jun 20 '16 at 19:13
  • Nope, even after setting this, it did not work, though I do see the settings in the ps -ef command. -Djava.util.logging.config.file=XXX/conf/logging.properties – user115391 Jun 23 '16 at 15:34
  • Does the tomcat server start via $CATALINA_HOME/bin/catalina.sh? The answer is come from descrption of that script. if environment variable `LOGGING_CONFIG` is specified, the default value will be replaced. – Beck Yang Jun 24 '16 at 14:07
  • This is the default linux install and I assume it uses the file /etc/init.d/tomcat6 to start. I have view only access for this file and I checked there and did not find anything related to catalina.out. When we install tomcat, then it is easy to change, but with this I am not sure how to change the location. Thanks – user115391 Jun 24 '16 at 16:10
  • `catalina.out` is writed by `java.util.logging`, you have to change the setting of `java.util.logging`. If your startup script similar to https://gist.github.com/FrankGrimm/1480319, you have to modify the line 134-142. So `LOGGING_CONFIG` could be exported to `catalina.sh`. – Beck Yang Jun 24 '16 at 22:45
  • The script is similar, but not the same. I will try to update via code and check. Thanks – user115391 Jun 29 '16 at 12:50