logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-808) RegexFilter does not work properly with RollingFileAppenders
Date Tue, 02 Sep 2014 21:07:20 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14118749#comment-14118749

Ralph Goers commented on LOG4J2-808:

In a Filter the 3 outcomes are:
ACCEPT - log events that match are logged regardless of any other filters.
NEUTRAL - continue processing filters to see if the event should be logged or not.
DENY - do not log the event.

If all the filters return NEUTRAL then the event is logged.

Note though that if an event passes the global filters and logger filters it might still be
filtered by Appender filters, even if it was accepted by a logger or global filter. 

I'm not exactly clear on what you want to do since printing all the logs obviously includes
printing all the logs related to the match.

If you want one Appender to get all events and another to only get some then put the filter
on the one that only gets some (or on the appender-ref) and don't put a filter on the other

> RegexFilter does not work properly with RollingFileAppenders 
> -------------------------------------------------------------
>                 Key: LOG4J2-808
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-808
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Filters
>    Affects Versions: 2.0-rc1
>            Reporter: Pranav Pratap
>              Labels: newbie
>             Fix For: 2.0-rc1
>         Attachments: HelloWorld.java, MainApp.java, log4j2.xml
> I am trying to use Regexfilter in RollingFileAppender. For 1st matching instance it retreived
the logger, but after that I different patttern but nothing is logged in the file. Here is
what I am using:
> {code}
> Main Class:
> public class MainApp {
>     /** 
>      * @param args
>      */
>      public static void main(String[] args) {
>          // TODO Auto-generated method stub
> 	final Logger logger = LogManager.getLogger(MainApp.class.getName());
> 	ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
>         HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
>         logger.trace("NPF:Trace:Entering Log4j2 Example.");
>         logger.debug("NTL:debug Entering Log4j2 Example.");
>         obj.getMessage();	
>         Company comp = new Company();
>         comp.setCompName("ANC");
>         comp.setEstablish(1889);
>         CompanyBusiness compBus =      (CompanyBusiness)context.getBean("compBus");
>         compBus.finaceBusiness(comp.getCompName(), comp.getEstablish());
>         logger.trace("NTL: Trace: Exiting Log4j2 Example.");
>     }
> }
> {code}
> log4j2.xml:
> {code}
> <?xml version="1.0" encoding="UTF-8" ?>
> <Configuration>
>  	<Appenders>
>              <Console name="STDOUT" target="SYSTEM_OUT">
>                  <PatternLayout pattern="%d{yyyy-MM-dd [%t] HH:mm:ss} %-5p %c{1}:%L
- %m%X%n" />
> 	    </Console>
> 	    <RollingFile name="RollingFile" fileName="C:\logTest\runtime\tla\els3.log"  append="true"
>     	                        filePattern="C:\logTest\runtime\tla\els3-%d{yyyy-MM-dd}-%i.log"
>                 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36}
- %m%X%n" />
>                 <RegexFilter regex=".*business*." onMatch="ACCEPT" onMismatch="DENY"/>

>                 <Policies>
>                     <SizeBasedTriggeringPolicy size="20 MB" />
>                 </Policies>     	
>             </RollingFile>		
> 	</Appenders>
> 	<Loggers>
> 		<Logger name="com.anc" level="trace"/>	
> 		<Root level="trace"> 
>     		    <AppenderRef ref="STDOUT" /> 
>     		    <AppenderRef ref="RollingFile"/> 
> 		</Root>	
> 	</Loggers>
> </Configuration>
> {code}
> When I ran for the first time, in my logfile I got logs having only "business" related
line. Latter I changed the patter from .*business*. to "business", logging did not happen
in file nor on the console. Also my application terminated without any kind of logging.
> Then I tried to revert back the pattern to .*business*., thereafter no logging happened
on the log file, but on the console all the log trace is printed. When I comment out the Regexfilter
after trying for long time, my logs was printed in the log file.
> I am not sure if this is a bug of Regexfilter works only for one time. Also if we do
not pass any patter matching characters, the application stops without any log printing either
on console or file.

This message was sent by Atlassian JIRA

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

View raw message