If you want to use log4j or log4j2 instead of standard Java logging API for your application, simply add the logger factory configuration to your classpath. First, create a file with the name

loggerfactory.properties

in one of your source/resource directories. Don't use a package name!
Put following content in it:

loggerfactory.properties
default.class=com.sibvisions.util.log.log4j.Log4jLoggerFactory

Don't forget to add the dependencies to your project (log4j or log4j2) and to configure:

log4j.properties
log4j.rootLogger=ERROR,stdout
 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n

or

log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
 
<Configuration>
 
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="%d %-5p [%t] %C{1} (%F:%L) - %m%n"/>
    </Console>
  </Appenders>
 
  <Loggers>
    <Root level="error">
      <AppenderRef ref="STDOUT"/>
    </Root>
  </Loggers>
 
</Configuration>

Another way to configure the logger factory is to set the system property:

LoggerFactory.default=com.sibvisions.util.log.log4j.Log4jLoggerFactory

as JVM start parameter (-DLoggerFactory.default=…).

This system property works in all JVx versions.

JVx before 2.8.5 also had different configuration options:

config.xml

(server zone)

config.xml
<?xml version="1.0" encoding="UTF-8"?>
 
<server>
   ...
 
  <logfactory>com.sibvisions.util.log.log4j.Log4jLoggerFactory</logfactory>
</server>
application.xml
application.xml
<application>
  ...
 
  <Launcher.logfactory>com.sibvisions.util.log.log4j.Log4jLoggerFactory</Launcher.logfactory>
</application>


These options are not supported in newer JVx versions because you had to configure logging in different places.


Note

We have sample files for log4j and log4j2 in our repository.