Question

I am just starting out on trying the spring tool suite v3.4.0 under oracle java 7u40 on Ubuntu Desktop AMD64 13.10 However, when I start the application from the command prompt, I get the following warning:

log4j:WARN No appenders could be found for logger (org.springsource.ide.eclipse.commons.core.templates.TemplateProcessor). log4j:WARN Please initialize the log4j system properly.

I probably need to configure log4j.properties somewhere, however I am not sure where and how I link the config to STS. Has anyone got a log4j.properties for STS and how do I link it to the STS startup.

I tried the following log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
  <appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </appenders>
  <loggers>
    <root level="trace">
      <appender-ref ref="Console"/>
    </root>
  </loggers>
</configuration>

And added the following environment variable:

export JAVA_OPTS=-Dlog4j.configurationFile=~/Log4j/log4j2.xml

However, I still get the same warning when starting STS.

Was it helpful?

Solution

You have a number of options:

  1. Specify the location of the log4j configuration file on the file system. The path in a file: URL must be absolute. On Windows, file: URLs start with either "file:/", or "file:///", and '/' characters replace '\' characters in the path. Your line would be:

    export JAVA_OPTS=-Dlog4j.configurationFile=file:/path/to/your/log4j2.xml
    
  2. Specify the location of the log4j configuration file relative to a classpath entry. If the "/path/to/your/" directory is on the classpath your line would be:

    export JAVA_OPTS=-Dlog4j.configurationFile=log4j2.xml
    
  3. Specify the location of log4J configuration file to be used for all JVMs. Your line would be:

    export _JAVA_OPTIONS=-Dlog4j.configurationFile=file:/path/to/your/log4j2.xml
    
  4. Specify the location of the log4j configuration file on the Java command line for your application. Your line would be:

    -Dlog4j.configurationFile=file:/path/to/your/log4j2.xml
    

In your question, you don't specify what application you are running, but these options will all work.

If you are trying to specify the log4j configuration to use in an application running on a JEE container, e.g. a web application, please refer to the log4j documentation.

I hope this helps you out.

OTHER TIPS

My original assumption and answer were incorrect.

Setting the JVM option -Dlog4j.debug=true revealed that Eclipse ignores the log4j.configurationFile property and looks for either log4j.xml or logj.properties on the classpath.

I do not know how to change the system classpath for Eclipse, so I put the log4j configuration in the JRE's endorsed directory. The steps are:

  1. Put your log4j configuration file in a jar file, say log4jconfig.jar
  2. Put that jar file in the JRE's endorsed directory. On my Windows 7 system, this is "...\JDK1.7.0\jre\lib\endorsed". If the directory does not exist, create it.

The log4j configuration I used is:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

    <appender name="Console" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="ALL" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" />
        </layout>
    </appender>

    <root>
        <level value="all" />
        <appender-ref ref="Console" />
    </root>

</log4j:configuration>

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top