logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tungathurthi, Chandra Kiran Bharadwaj" <chandra.tungathur...@rwth-aachen.de>
Subject Re: Log4j2.7 - Adding same appender to multiple loggers?
Date Sun, 04 Dec 2016 13:34:11 GMT
Hi Gary,

I tried to see if there was any work around. unfortunately I couldn't find any. this is why
I extended the standard Log4j2 to create new tags. This served my purpose. 

Best,
Chandra



----
Best regards,
Chandra
about.me/tckb

________________________________________
From: Gary Gregory <garydgregory@gmail.com>
Sent: Saturday, December 3, 2016 21:26
To: Log4J Users List
Subject: Re: Log4j2.7 - Adding same appender to multiple loggers?

Where are you on this?

Gary

On Mon, Oct 10, 2016 at 2:00 AM, Tungathurthi, Chandra Kiran Bharadwaj <
chandra.tungathurthi@rwth-aachen.de> wrote:

> Hi users,
>
>
> I have been stuck with a problem eating way my time and energy.
>
> My goal: create one generic appender with parameters which can be used for
> multiple loggers and the parameters to it will be furnished during runtime.
> Thus, creating a "dynamic" appender which spans through multiple loggers.
>
>
> This is my
>
> <Routing name="defaultAppender">
>     <Routes>
>         <Script name="RoutingInit" language="JavaScript">
>             <![CDATA[
>             if (logEvent.getLevel().intLevel() >= 400) {
>                 "info-logs";
>             } else {
>                 "error-logs";
>             }
>             ]]>
>         </Script>
>         <Route key="info-logs">
>             <RollingRandomAccessFile name="rrafAppenderDsp-${ctx:file}"
>                                      fileName="${ctx:dir}/${ctx:file}.log"
>                                      filePattern="${ctx:gzip-dir}/$
> {ctx:file}_%d{dd-MM-yyyy}_%i.log.gz"
>                                      append="true" immediateFlush="false"
>                                      bufferSize="${ctx:bufferSize}">
>                 <PatternLayout>
>                     <pattern>${ctx:pattern}</pattern>
>                 </PatternLayout>
>                 <Policies>
>                     <SizeBasedTriggeringPolicy
> size="${ctx:rollover-filesize}"/>
>                 </Policies>
>                 <DefaultRolloverStrategy compressionLevel="${ctx:gzip-
> compression}">
>                     <Delete basePath="${ctx:gzip-dir}">
>                         <IfFileName glob="*/${ctx:file}_*.log.gz"/>
>                         <IfLastModified age="${ctx:gzip-purgetime}"/>
>                     </Delete>
>                 </DefaultRolloverStrategy>
>             </RollingRandomAccessFile>
>         </Route>
>         <Route key="error-logs">
>             <RollingRandomAccessFile name="rrafAppenderDsp"
>                                      fileName="${ctx:dir}/${ctx:
> file}_errors.log"
>                                      filePattern="${ctx:gzip-dir}/$
> {ctx:file}_errors_%d{dd-MM-yyyy}_%i.log.gz"
>                                      append="true" immediateFlush="false"
>                                      bufferSize="${ctx:bufferSize}">
>                 <PatternLayout>
>                     <pattern>${root.linePattern}</pattern>
>                 </PatternLayout>
>                 <Policies>
>                     <SizeBasedTriggeringPolicy
> size="${ctx:rollover-filesize}"/>
>                 </Policies>
>                 <DefaultRolloverStrategy compressionLevel="${ctx:gzip-
> compression}">
>                     <Delete basePath="${ctx:gzip-dir}">
>                         <IfFileName glob="*/${ctx:file}_errors_*.log.gz"/>
>                         <IfLastModified age="${ctx:gzip-purgetime}"/>
>                     </Delete>
>                 </DefaultRolloverStrategy>
>             </RollingRandomAccessFile>
>         </Route>
>     </Routes>
> </Routing>
>
> <Logger name="logger1" level="INFO" additivity="false">
>     <AppenderRef ref="defaultAppender"/>
> </Logger>
> <Logger name="logger2" level="INFO" additivity="false">
>     <AppenderRef ref="defaultAppender"/>
> </Logger>
> <Logger name="logger3" level="INFO" additivity="false">
>     <AppenderRef ref="defaultAppender"/>
> </Logger>?
>
>
> the contextual params are filled as follows
>
>
> // this called by each logger while logging
>
> public void log(Level logingLevel, String data) {
>
> // this loads the ?contextual params into ThreadContext
>
>    loadPropertiesToContext();
>
>
>    logger.log(logingLevel, data);
>
>     ThreadContext.clearMap();
>
> }?
>
>
>
> Now, the problem is, the same settings works fine for one logger , but as
> soon as l use the same appender for multiple loggers, the data is being
> mixed up and if logger1 has to written in file1 and logger2 to file2, both
> the logevents are being written in file1. As I imagined, routing appender
> uses current threadcontext to dynamically 'route' the events, the above
> settings should work.
>
>
> Has anyone had the same experience? or would like to pitch in on how to
> make this work ?
>
>
> Cheers!
>
> Chandra?
>



--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message