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

Ralph Goers edited comment on LOG4J2-808 at 9/3/14 3:55 PM:
------------------------------------------------------------

Expected Results:

Case 1: You should only get events with NPE in the message text.
Case 2: You should see all log events.
Case 3: You should see all log events.

Filtering simply does not work the way you think it does.  They are very 
similar to firewall rules.  The event is checked to see if it matches or 
doesn't match the filter. If it matches the onMatch action is taken otherwise 
the onMismatch action is taken. If the action is ACCEPT the event is logged. If 
it is DENY the event is ignored. If it is NEUTRAL then further filtering is 
performed, if there are any, or the event is logged if not.

If you look at case 2 and 3 you will discover what you are asking for is not 
possible. In case 2 you are saying that if an event does not contain "NPE" then 
NEUTRAL should cause it to NOT be logged. In case 3 you are saying that if an 
event does not contain "XYZ" then NEUTRAL should cause the event to be logged. 
There are obviously opposite results and only one of them can happen.

When you say "the pattern is not present in my code" I have a feeling that you 
are somehow thinking that the pattern matching is being done across a bunch of 
events. It is not. Each log event is individually compared against the pattern 
and the result of the comparison has nothing to do with whether other events 
might have passed or failed. 


was (Author: [email protected]):
Expected Results:

Case 1: You should only get events with NPE in the message text.
Case 2: You should see all log events.
Case 3: You should see all log events.

Filtering simply does not work the way you think it does.  They are very 
similar to firewall rules.  The event is checked to see if it matches or 
doesn't match the filter. If it matches the onMatch action is taken otherwise 
the onMismatch action is taken. If the action is ACCEPT the event is logged. If 
it is DENY the event is ignored. If it is NEUTRAL then further filtering is 
performed, if there are any, or the event is logged if not.

If you look at case 2 and 3 you will discover what you are asking for is not 
possible. In case 2 you are saying that if an event does not contain "NPE" then 
NEUTRAL should cause it to not be logged. In case 3 you are saying that if an 
event does not contain "XYZ" then NEUTRAL should cause the event to NOT be 
logged. There are obviously opposite results and only one of them can happen.

When you say "the pattern is not present in my code" I have a feeling that you 
are somehow thinking that the pattern matching is being done across a bunch of 
events. It is not. Each log event is individually compared against the pattern 
and the result of the comparison has nothing to do with whether other events 
might have passed or failed. 

> 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
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to