Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
jvx:common:util:log4j [2020/01/22 10:49]
admin
jvx:common:util:log4j [2020/01/24 09:33]
admin
Line 2: Line 2:
 ~~Title: Log4j instead of Logging API~~ ~~Title: Log4j instead of Logging API~~
  
-If you want to use log4j or log4j2 instead of standard Java logging API for your application,​ simply configure the logger ​via config.xml ​of your server zone:+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: 
 + 
 +<file properties loggerfactory.properties>​ 
 +default.class=com.sibvisions.util.log.log4j.Log4jLoggerFactory 
 +</​file>​ 
 + 
 +Don't forget to add the dependencies to your project (log4j or log4j2) and to configure:​ 
 + 
 +<file properties 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 
 +</​file>​ 
 + 
 +or 
 + 
 +<file xml 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>​ 
 +</​file>​ 
 + 
 +Another option, to configure the logger ​factory is to set the system property:  
 + 
 +<​code>​ 
 +LoggerFactory.default=com.sibvisions.util.log.log4j.Log4jLoggerFactory 
 +</​code>​ 
 +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)
  
 <file xml config.xml>​ <file xml config.xml>​
Line 8: Line 64:
  
 <​server>​ <​server>​
 +   ...
   ​   ​
   <​logfactory>​com.sibvisions.util.log.log4j.Log4jLoggerFactory</​logfactory>​   <​logfactory>​com.sibvisions.util.log.log4j.Log4jLoggerFactory</​logfactory>​
- 
-  ... 
 </​server>​ </​server>​
 </​file>​ </​file>​
  
-It's also possible to use log4j(2) for your client ​application. ​Simply set the application parameter:+== application.xml == 
  
-<​file ​script+<​file ​xml application.xml
-Launcher.logfactory+<​application>​ 
 +  ... 
 +   
 +  <Launcher.logfactory>​com.sibvisions.util.log.log4j.Log4jLoggerFactory</​Launcher.logfactory>​ 
 +</​application>​
 </​file>​ </​file>​
  
-as command-line parameter or via application.xml. There'​s also a constant ​in javax.rad.application.ILauncher with the name PARAM_LOGFACTORY. +\\  
- +This options are not supported ​in newer JVx versions ​because you had to configure logging in different places.
-We don't recommend other log APIs than java logging API if you start your JVx application as an Applet, ​because ​it makes deployment more complex. But it's possible if you want.+
  
 \\  \\ 
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information