I know there is allot of questions been asked on this but i have been trying to get this to work for few day's and i am not any more forward then when i started.
i have tried to use -Dlog4j.configuration=file:/path/to/log4j.properties
and -Dlog4j.debug
in eclipse vm arguments (under debug & run) and get no output
I have tried to use .properties and .xml but no joy
Tried to put the .xml and .properties files at the root, in the src and in an external folder which i added to my classpath ... still no joy
I think its using another .xml or .properties files in another lib/jar but because i cant get any debug to work i am finding very difficult to track what i am doing wrong here...
any help would be great! below is the code .. only the error message get's printed.
I have download (http://logging.apache.org/log4j/2.x/download.html) and imported into my app the
log4j-api-2.0-beta8.jar
log4j-core-2.0-beta8
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CucmServMonitor
{
private static final Logger logger = LogManager.getLogger(CucmServMonitor.class.getName())
public static void main(String[] args)
{
logger.error("testing ERROR level");
logger.trace("exiting application");
System.out.println(logger.getName());
}
}
the xml file i am using just now log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="WARN">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders>
<loggers>
<root level="debug">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>
Manage to figure this one out. The hint was here.
http://pic.dhe.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-112.htm
I needed to add a "class folder" of where the log4j2.xml was located and then make sure it was at TOP of the list:
Right click on your project and go to properties
Then follow the step shown below. After adding the folder make sure its at the top and then click ok
Or... just create a resources directory like src/test/resources and add the log4j.xml file to that dir and then make that directory a source folder. Then eclipse will automatically copy the file to the the classes dir and there you have it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With