log4j.xml with system environment and Tomcat 7

  • Posted August 7, 2014

Hello, I have some problem trying use log4j with System environment. This is my log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC  "-//APACHE//DTD LOG4J 1.2//EN" "">

<log4j:configuration xmlns:log4j="">
	<appender name="main" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{HH:mm:ss} %5p [%-20c{1}] %m%n" />

	<appender name="file" class="org.apache.log4j.RollingFileAppender">
		<param name="append" value="false" />
		<param name="maxFileSize" value="10MB" />
		<param name="maxBackupIndex" value="10" />
		<param name="file" value="${CATALINA_HOME}/logs/info.log" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />

	<category name="org.jboss.logging">
		<priority value="WARN" />
		<appender-ref ref="main" />

	<category name="org.jboss.weld">
		<priority value="INFO" />
		<appender-ref ref="main" />

	<logger name="controller">
		<level value="INFO" />
		<appender-ref ref="main" />
		<appender-ref ref="file" />
	</logger >

I can see the logs on catalina.out, but is not creating the info.log.

Works fine on my computer, lol. Ty,


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Does ${CATALINA_HOME}/logs/info.log exist? You might need to create the file and allow Tomcat to write to it.

If catalina.out works fine, you can transfer its permissions to info.log:

sudo chmod --reference /path/to/catalina.out /path/to/info.log
sudo chown --reference /path/to/catalina.out /path/to/info.log