java - Redirect Jersey JUL logging to Log4j2 -


i need redirect jersey request/response log log4j2.

i have jersey logging enabled using code on applicationjaxrs extends application:

@override public set<class<?>> getclasses() {     return new hashset<class<?>>() {{         add(loggingfilter.class);     }};     } 

it seems jersey uses jul (java logging) internally , default output stdout. @ moment can see stdout on eclipse console.

the log4j2 documentation have section jdk logging adapter. says

to use jdk logging adapter, must set system property java.util.logging.manager org.apache.logging.log4j.jul.logmanager

this must done either through command line (i.e., using -djava.util.logging.manager=org.apache.logging.log4j.jul.logmanager argument) or using system.setproperty() before calls made logmanager or logger.

to call system.setproperty(*) before logger call i've tried put on @postconstruct in aplication class.

@postconstruct     public void init() {         system.setproperty("java.util.logging.manager", "org.apache.logging.log4j.jul.logmanager");     } 

i log on logging files.

this log4j2.xml:

    <appenders>         <rollingfile name="rollingfile" filename="${log-path}/${name}.log"              filepattern="${log-path}/${date:yyyy-mm}/${name}-%d{yyyy-mm-dd}-%i.log">             <patternlayout>                 <pattern>%d{dd-mm-yy hh:mm:ss,sss} %-5p [%t] (%f:%l) - %m%n</pattern>             </patternlayout>             <policies>                 <timebasedtriggeringpolicy interval="1" modulate="true"/>             </policies>             <defaultrolloverstrategy max="10" />         </rollingfile>         <console name="console" target="system_out">             <patternlayout pattern="%d %-5p [%t] %c{2} (%f:%l) - %m%n" />         </console>     </appenders>     <loggers>         <root level="debug">             <appenderref ref="console" level="debug"/>             <appenderref ref="rollingfile" level="debug"/>         </root>     </loggers> </configuration> 

i imagine have set system property @ launch. add code init method see if setting system property worked.

@postconstruct public void init() {     string cn = "org.apache.logging.log4j.jul.logmanager";     system.setproperty("java.util.logging.manager", cn);     logmanager lm = logmanager.getlogmanager();     if (!cn.equals(lm.getclass().getname())) {        try {            classloader.getsystemclassloader().loadclass(cn);        } catch (classnotfoundexception cnfe) {           throw new illegalstateexception("jars not in system class path.", cnfe);        }        throw new illegalstateexception("found " + lm.getclass().getname() + " set launch param instead.");     } } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -