log4j2 - duplicating logs in Console & RollingFile -


hey wondering if possible have same output in console in file output.

here xml config.

<?xml version="1.0" encoding="utf-8"?> <configuration status="warn" name="log4j2 logs">     <properties>         <property name="basepath">./logs</property>     </properties>       <appenders>          <rollingfile name="file" filename="${basepath}/activatemaintenancepage.logs"                               filepattern="${basepath}/activatemaintenancepage-%d{yyyy-mm-dd}">       <patternlayout header="logging start%n%n" footer="%n%nlogging end"                      pattern="%3sn %30d{default}    [%m] %-7level %c{30} - %m%n" />        <policies>               <onstartuptriggeringpolicy minsize="0"/>         <timebasedtriggeringpolicy />         <sizebasedtriggeringpolicy size="500 mb"/>       </policies>     </rollingfile>       <console name="console" target="system_out">       <patternlayout header="logging start%n%n" footer="%n%nlogging end"                      pattern="%3sn %30d{default}    [%m] %-7level %c{30} - %m%n" />     </console>        </appenders>         <loggers>                  <root level="trace">                 <appenderref ref="console" level="error"/>           <appenderref ref="file" level="trace"/>              </root>   </loggers>  </configuration> 

output in rollingfile

  1        2017-07-25 11:16:36,762    [initializechrome] info    class testng.simsettings - web chrome driver initilized.   2        2017-07-25 11:16:36,762    [lambda$0] info    class testng.simsettings - opening... http://msrvaq11vm.technomedia.ca/sigal_60/2017sp1/sp_polymont/_sim/prod sp2 2016 sim...   3        2017-07-25 11:16:47,926    [initilizeallelements] info    class testng.simsettings - @findby elements have been initilized.   4        2017-07-25 11:16:48,006    [change1stlevelframe] info    class testng.simsettings - changing target 1st level frame.   5        2017-07-25 11:16:49,719    [entercredentials] info    class testng.simsettings - username & password: success! 

and empty in console. if change

<appenderref ref="console" level="error"/>   

to "trace"

it 2,4,6....in console , in file 1,3,5,7... understandable.

but question how can have both same log-level (trace) output in console , file? (adding tag package name , level did not work)

related question: log4j2 xml configuration - log file , console (with different levels)

i'm not sure if read question correctly seems want render unique value in log output, such same log event has same unique value in console log , file log output.

the sequence number pattern converter increment every time log event rendered. same log event rendered separately each appender, different appenders never have same sequence number.

there number of alternatives. 1 idea include %nano nanotime in pattern layout. value captured when application makes logging call , same appenders. alternative create custom log4j2 pattern converter or lookup.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -