log4j - StringMatchFilter still logging unmatched logs












1















Hope anyone could help me with this issue, so basically I am using log4j-1.2.17 and sorry, I can't update it to log4j2.
As the title suggests, I need to do the following,




  1. I am trying to create an audit.log file which only logs information that has a certain string element (e.g., USER ACTION) and doesn't log anything else.

  2. I have another operations.log that will log everything but not the one with String USER ACTION


My log4j.properties file looks something like this,



log4j.logger.com.ssl=INFO, Output 
log4j.logger.com.ssl=INFO, Audit

log4j.appender.Output=org.apache.log4j.DailyRollingFileAppender
log4j.appender.Output.DatePattern='.'yyyy-MM-dd
log4j.appender.Output.File=/var/log/operational/operations.log
log4j.appender.Output.layout=org.apache.log4j.PatternLayout
log4j.appender.Output.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
log4j.appender.Output.Threshold=TRACE
log4j.appender.Output.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.Output.filter.1.StringToMatch=USER ACTION
log4j.appender.Output.filter.1.AcceptOnMatch=false
log4j.appender.Output.filter=org.apache.log4j.varia.DenyAllFilter

log4j.appender.Audit=org.apache.log4j.DailyRollingFileAppender
log4j.appender.Audit.DatePattern='.'yyyy-MM-dd
log4j.appender.Audit.File=/var/log/operational/audit.log
log4j.appender.Audit.Threshold=TRACE
log4j.appender.Audit.layout=org.apache.log4j.PatternLayout
log4j.appender.Audit.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
log4j.appender.Audit.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.Audit.filter.1.StringToMatch=USER ACTION
log4j.appender.Audit.filter.1.AcceptOnMatch=true
log4j.appender.Audit.filter=org.apache.log4j.varia.DenyAllFilter


Inside the Java Code, I have something like this,



private static final String AUDIT_LOG_PREFIX = "USER ACTION";
logger.info("Just testing if this appears before the one below it");
logger.info("[" + AUDIT_LOG_PREFIX + "] - User Details Updated by User : "+ r.getUserName());


The log output I get is as follows,



operational.log



2018-11-22 10:55:31 INFO  [http-nio-8080-exec-179] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)


audit.log



2018-11-22 10:58:51 INFO  [http-nio-8080-exec-192] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] [USER ACTION] - User Details Updated by User : adminuser


So really hoping that audit.log doesn't display the first log entry and just displays the one with USER ACTION string.



Any help or advice will be greatly appreciated, Thank you










share|improve this question



























    1















    Hope anyone could help me with this issue, so basically I am using log4j-1.2.17 and sorry, I can't update it to log4j2.
    As the title suggests, I need to do the following,




    1. I am trying to create an audit.log file which only logs information that has a certain string element (e.g., USER ACTION) and doesn't log anything else.

    2. I have another operations.log that will log everything but not the one with String USER ACTION


    My log4j.properties file looks something like this,



    log4j.logger.com.ssl=INFO, Output 
    log4j.logger.com.ssl=INFO, Audit

    log4j.appender.Output=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.Output.DatePattern='.'yyyy-MM-dd
    log4j.appender.Output.File=/var/log/operational/operations.log
    log4j.appender.Output.layout=org.apache.log4j.PatternLayout
    log4j.appender.Output.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
    log4j.appender.Output.Threshold=TRACE
    log4j.appender.Output.filter.1=org.apache.log4j.varia.StringMatchFilter
    log4j.appender.Output.filter.1.StringToMatch=USER ACTION
    log4j.appender.Output.filter.1.AcceptOnMatch=false
    log4j.appender.Output.filter=org.apache.log4j.varia.DenyAllFilter

    log4j.appender.Audit=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.Audit.DatePattern='.'yyyy-MM-dd
    log4j.appender.Audit.File=/var/log/operational/audit.log
    log4j.appender.Audit.Threshold=TRACE
    log4j.appender.Audit.layout=org.apache.log4j.PatternLayout
    log4j.appender.Audit.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
    log4j.appender.Audit.filter.1=org.apache.log4j.varia.StringMatchFilter
    log4j.appender.Audit.filter.1.StringToMatch=USER ACTION
    log4j.appender.Audit.filter.1.AcceptOnMatch=true
    log4j.appender.Audit.filter=org.apache.log4j.varia.DenyAllFilter


    Inside the Java Code, I have something like this,



    private static final String AUDIT_LOG_PREFIX = "USER ACTION";
    logger.info("Just testing if this appears before the one below it");
    logger.info("[" + AUDIT_LOG_PREFIX + "] - User Details Updated by User : "+ r.getUserName());


    The log output I get is as follows,



    operational.log



    2018-11-22 10:55:31 INFO  [http-nio-8080-exec-179] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)


    audit.log



    2018-11-22 10:58:51 INFO  [http-nio-8080-exec-192] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
    2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] [USER ACTION] - User Details Updated by User : adminuser


    So really hoping that audit.log doesn't display the first log entry and just displays the one with USER ACTION string.



    Any help or advice will be greatly appreciated, Thank you










    share|improve this question

























      1












      1








      1


      1






      Hope anyone could help me with this issue, so basically I am using log4j-1.2.17 and sorry, I can't update it to log4j2.
      As the title suggests, I need to do the following,




      1. I am trying to create an audit.log file which only logs information that has a certain string element (e.g., USER ACTION) and doesn't log anything else.

      2. I have another operations.log that will log everything but not the one with String USER ACTION


      My log4j.properties file looks something like this,



      log4j.logger.com.ssl=INFO, Output 
      log4j.logger.com.ssl=INFO, Audit

      log4j.appender.Output=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.Output.DatePattern='.'yyyy-MM-dd
      log4j.appender.Output.File=/var/log/operational/operations.log
      log4j.appender.Output.layout=org.apache.log4j.PatternLayout
      log4j.appender.Output.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
      log4j.appender.Output.Threshold=TRACE
      log4j.appender.Output.filter.1=org.apache.log4j.varia.StringMatchFilter
      log4j.appender.Output.filter.1.StringToMatch=USER ACTION
      log4j.appender.Output.filter.1.AcceptOnMatch=false
      log4j.appender.Output.filter=org.apache.log4j.varia.DenyAllFilter

      log4j.appender.Audit=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.Audit.DatePattern='.'yyyy-MM-dd
      log4j.appender.Audit.File=/var/log/operational/audit.log
      log4j.appender.Audit.Threshold=TRACE
      log4j.appender.Audit.layout=org.apache.log4j.PatternLayout
      log4j.appender.Audit.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
      log4j.appender.Audit.filter.1=org.apache.log4j.varia.StringMatchFilter
      log4j.appender.Audit.filter.1.StringToMatch=USER ACTION
      log4j.appender.Audit.filter.1.AcceptOnMatch=true
      log4j.appender.Audit.filter=org.apache.log4j.varia.DenyAllFilter


      Inside the Java Code, I have something like this,



      private static final String AUDIT_LOG_PREFIX = "USER ACTION";
      logger.info("Just testing if this appears before the one below it");
      logger.info("[" + AUDIT_LOG_PREFIX + "] - User Details Updated by User : "+ r.getUserName());


      The log output I get is as follows,



      operational.log



      2018-11-22 10:55:31 INFO  [http-nio-8080-exec-179] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)


      audit.log



      2018-11-22 10:58:51 INFO  [http-nio-8080-exec-192] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
      2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] [USER ACTION] - User Details Updated by User : adminuser


      So really hoping that audit.log doesn't display the first log entry and just displays the one with USER ACTION string.



      Any help or advice will be greatly appreciated, Thank you










      share|improve this question














      Hope anyone could help me with this issue, so basically I am using log4j-1.2.17 and sorry, I can't update it to log4j2.
      As the title suggests, I need to do the following,




      1. I am trying to create an audit.log file which only logs information that has a certain string element (e.g., USER ACTION) and doesn't log anything else.

      2. I have another operations.log that will log everything but not the one with String USER ACTION


      My log4j.properties file looks something like this,



      log4j.logger.com.ssl=INFO, Output 
      log4j.logger.com.ssl=INFO, Audit

      log4j.appender.Output=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.Output.DatePattern='.'yyyy-MM-dd
      log4j.appender.Output.File=/var/log/operational/operations.log
      log4j.appender.Output.layout=org.apache.log4j.PatternLayout
      log4j.appender.Output.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
      log4j.appender.Output.Threshold=TRACE
      log4j.appender.Output.filter.1=org.apache.log4j.varia.StringMatchFilter
      log4j.appender.Output.filter.1.StringToMatch=USER ACTION
      log4j.appender.Output.filter.1.AcceptOnMatch=false
      log4j.appender.Output.filter=org.apache.log4j.varia.DenyAllFilter

      log4j.appender.Audit=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.Audit.DatePattern='.'yyyy-MM-dd
      log4j.appender.Audit.File=/var/log/operational/audit.log
      log4j.appender.Audit.Threshold=TRACE
      log4j.appender.Audit.layout=org.apache.log4j.PatternLayout
      log4j.appender.Audit.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
      log4j.appender.Audit.filter.1=org.apache.log4j.varia.StringMatchFilter
      log4j.appender.Audit.filter.1.StringToMatch=USER ACTION
      log4j.appender.Audit.filter.1.AcceptOnMatch=true
      log4j.appender.Audit.filter=org.apache.log4j.varia.DenyAllFilter


      Inside the Java Code, I have something like this,



      private static final String AUDIT_LOG_PREFIX = "USER ACTION";
      logger.info("Just testing if this appears before the one below it");
      logger.info("[" + AUDIT_LOG_PREFIX + "] - User Details Updated by User : "+ r.getUserName());


      The log output I get is as follows,



      operational.log



      2018-11-22 10:55:31 INFO  [http-nio-8080-exec-179] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)


      audit.log



      2018-11-22 10:58:51 INFO  [http-nio-8080-exec-192] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
      2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] [USER ACTION] - User Details Updated by User : adminuser


      So really hoping that audit.log doesn't display the first log entry and just displays the one with USER ACTION string.



      Any help or advice will be greatly appreciated, Thank you







      java logging log4j






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 11:58









      rac3b3nn0nrac3b3nn0n

      366318




      366318
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430536%2flog4j-stringmatchfilter-still-logging-unmatched-logs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430536%2flog4j-stringmatchfilter-still-logging-unmatched-logs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith