Log4j2 issue when use multiple custom rolling file appender












1















My log4j2 properties file looks like below-



When I tried to access the appender by using the following code



private static final Logger LOGGER = LogManager.getLogger("ejdk");
LOGGER.info("test");


It is logging the entry in SeriesInResponse appender not in the ejdk appender. My log4j2 has multiple custom appender. I need to use different appender in different class file and it should log the entry in the correct files.



rootLogger.level = WARN
appenders = sdw,ejdk,SeriesInResponse
rootLogger.appenderRefs = sdw
rootLogger.appenderRef.sdw.ref = RollingFile
appender.sdw.type = RollingFile
appender.sdw.name = RollingFile
appender.sdw.fileName=G:/ApplicationLogs/sdw_internal_server.log
appender.sdw.filePattern=G:/ApplicationLogs/sdw_internal_server-%d{yyyy-MM-
dd}.log.zip
appender.sdw.layout.type = PatternLayout
appender.sdw.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
appender.sdw.policies.type = Policies

# Rotate log file each day and keep 60 days worth
appender.sdw.policies.time.type = TimeBasedTriggeringPolicy
appender.sdw.policies.time.interval = 1
appender.sdw.policies.time.modulate = true
appender.sdw.strategy.type = DefaultRolloverStrategy
appender.sdw.strategy.delete.type = Delete
appender.sdw.strategy.delete.basePath = ${application.log}
appender.sdw.strategy.delete.maxDepth = 1
appender.sdw.strategy.delete.ifLastModified.type = IfLastModified
# Delete files older than 30 days
appender.sdw.strategy.delete.ifLastModified.age = 30d

loggers = ejdk,SeriesInResponse

logger.ejdk.name = ejdk
logger.ejdk.level = INFO
logger.ejdk.additivity = false
logger.ejdk.appenderRef.ejdk.ref = RollingFile
appender.ejdk.type = RollingFile
appender.ejdk.name = RollingFile
appender.ejdk.fileName=G:/ApplicationLogs/sdw_internal_ejdk.log
appender.ejdk.filePattern=G:/ApplicationLogs/sdw_internal_ejdk.log-%d{yyyy-
MM-dd}.log.zip
appender.ejdk.layout.type = PatternLayout
appender.ejdk.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
appender.ejdk.policies.type = Policies

# Rotate log file each day and keep 60 days worth
appender.ejdk.policies.time.type = TimeBasedTriggeringPolicy
appender.ejdk.policies.time.interval = 1
appender.ejdk.policies.time.modulate = true
appender.ejdk.strategy.type = DefaultRolloverStrategy
appender.ejdk.strategy.delete.type = Delete
appender.ejdk.strategy.delete.basePath = ${application.log}
appender.ejdk.strategy.delete.maxDepth = 1
appender.ejdk.strategy.delete.ifLastModified.type = IfLastModified
# Delete files older than 30 days
appender.ejdk.strategy.delete.ifLastModified.age = 30d

logger.SeriesInResponse.name = SeriesInResponse
logger.SeriesInResponse.level = INFO
logger.SeriesInResponse.additivity = false
logger.SeriesInResponse.appenderRef.SeriesInResponse.ref = RollingFile
appender.SeriesInResponse.type = RollingFile
appender.SeriesInResponse.name = RollingFile
appender.SeriesInResponse.fileName=G:/ApplicationLogs/sdw_internal_series_responses.log
appender.SeriesInResponse.filePattern=G:/ApplicationLogs/sdw_internal_series_responses.log-%d{yyyy-MM-dd}.log.zip
appender.SeriesInResponse.layout.type = PatternLayout
appender.SeriesInResponse.layout.pattern = %d{ISO8601} %m%n
appender.SeriesInResponse.policies.type = Policies

# Rotate log file each day and keep 60 days worth
appender.SeriesInResponse.policies.time.type = TimeBasedTriggeringPolicy
appender.SeriesInResponse.policies.time.interval = 1
appender.SeriesInResponse.policies.time.modulate = true
appender.SeriesInResponse.strategy.type = DefaultRolloverStrategy
appender.SeriesInResponse.strategy.delete.type = Delete
appender.SeriesInResponse.strategy.delete.basePath = ${application.log}
appender.SeriesInResponse.strategy.delete.maxDepth = 1
appender.SeriesInResponse.strategy.delete.ifLastModified.type = IfLastModified
# Delete files older than 30 days
appender.SeriesInResponse.strategy.delete.ifLastModified.age = 30d









share|improve this question





























    1















    My log4j2 properties file looks like below-



    When I tried to access the appender by using the following code



    private static final Logger LOGGER = LogManager.getLogger("ejdk");
    LOGGER.info("test");


    It is logging the entry in SeriesInResponse appender not in the ejdk appender. My log4j2 has multiple custom appender. I need to use different appender in different class file and it should log the entry in the correct files.



    rootLogger.level = WARN
    appenders = sdw,ejdk,SeriesInResponse
    rootLogger.appenderRefs = sdw
    rootLogger.appenderRef.sdw.ref = RollingFile
    appender.sdw.type = RollingFile
    appender.sdw.name = RollingFile
    appender.sdw.fileName=G:/ApplicationLogs/sdw_internal_server.log
    appender.sdw.filePattern=G:/ApplicationLogs/sdw_internal_server-%d{yyyy-MM-
    dd}.log.zip
    appender.sdw.layout.type = PatternLayout
    appender.sdw.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
    appender.sdw.policies.type = Policies

    # Rotate log file each day and keep 60 days worth
    appender.sdw.policies.time.type = TimeBasedTriggeringPolicy
    appender.sdw.policies.time.interval = 1
    appender.sdw.policies.time.modulate = true
    appender.sdw.strategy.type = DefaultRolloverStrategy
    appender.sdw.strategy.delete.type = Delete
    appender.sdw.strategy.delete.basePath = ${application.log}
    appender.sdw.strategy.delete.maxDepth = 1
    appender.sdw.strategy.delete.ifLastModified.type = IfLastModified
    # Delete files older than 30 days
    appender.sdw.strategy.delete.ifLastModified.age = 30d

    loggers = ejdk,SeriesInResponse

    logger.ejdk.name = ejdk
    logger.ejdk.level = INFO
    logger.ejdk.additivity = false
    logger.ejdk.appenderRef.ejdk.ref = RollingFile
    appender.ejdk.type = RollingFile
    appender.ejdk.name = RollingFile
    appender.ejdk.fileName=G:/ApplicationLogs/sdw_internal_ejdk.log
    appender.ejdk.filePattern=G:/ApplicationLogs/sdw_internal_ejdk.log-%d{yyyy-
    MM-dd}.log.zip
    appender.ejdk.layout.type = PatternLayout
    appender.ejdk.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
    appender.ejdk.policies.type = Policies

    # Rotate log file each day and keep 60 days worth
    appender.ejdk.policies.time.type = TimeBasedTriggeringPolicy
    appender.ejdk.policies.time.interval = 1
    appender.ejdk.policies.time.modulate = true
    appender.ejdk.strategy.type = DefaultRolloverStrategy
    appender.ejdk.strategy.delete.type = Delete
    appender.ejdk.strategy.delete.basePath = ${application.log}
    appender.ejdk.strategy.delete.maxDepth = 1
    appender.ejdk.strategy.delete.ifLastModified.type = IfLastModified
    # Delete files older than 30 days
    appender.ejdk.strategy.delete.ifLastModified.age = 30d

    logger.SeriesInResponse.name = SeriesInResponse
    logger.SeriesInResponse.level = INFO
    logger.SeriesInResponse.additivity = false
    logger.SeriesInResponse.appenderRef.SeriesInResponse.ref = RollingFile
    appender.SeriesInResponse.type = RollingFile
    appender.SeriesInResponse.name = RollingFile
    appender.SeriesInResponse.fileName=G:/ApplicationLogs/sdw_internal_series_responses.log
    appender.SeriesInResponse.filePattern=G:/ApplicationLogs/sdw_internal_series_responses.log-%d{yyyy-MM-dd}.log.zip
    appender.SeriesInResponse.layout.type = PatternLayout
    appender.SeriesInResponse.layout.pattern = %d{ISO8601} %m%n
    appender.SeriesInResponse.policies.type = Policies

    # Rotate log file each day and keep 60 days worth
    appender.SeriesInResponse.policies.time.type = TimeBasedTriggeringPolicy
    appender.SeriesInResponse.policies.time.interval = 1
    appender.SeriesInResponse.policies.time.modulate = true
    appender.SeriesInResponse.strategy.type = DefaultRolloverStrategy
    appender.SeriesInResponse.strategy.delete.type = Delete
    appender.SeriesInResponse.strategy.delete.basePath = ${application.log}
    appender.SeriesInResponse.strategy.delete.maxDepth = 1
    appender.SeriesInResponse.strategy.delete.ifLastModified.type = IfLastModified
    # Delete files older than 30 days
    appender.SeriesInResponse.strategy.delete.ifLastModified.age = 30d









    share|improve this question



























      1












      1








      1








      My log4j2 properties file looks like below-



      When I tried to access the appender by using the following code



      private static final Logger LOGGER = LogManager.getLogger("ejdk");
      LOGGER.info("test");


      It is logging the entry in SeriesInResponse appender not in the ejdk appender. My log4j2 has multiple custom appender. I need to use different appender in different class file and it should log the entry in the correct files.



      rootLogger.level = WARN
      appenders = sdw,ejdk,SeriesInResponse
      rootLogger.appenderRefs = sdw
      rootLogger.appenderRef.sdw.ref = RollingFile
      appender.sdw.type = RollingFile
      appender.sdw.name = RollingFile
      appender.sdw.fileName=G:/ApplicationLogs/sdw_internal_server.log
      appender.sdw.filePattern=G:/ApplicationLogs/sdw_internal_server-%d{yyyy-MM-
      dd}.log.zip
      appender.sdw.layout.type = PatternLayout
      appender.sdw.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
      appender.sdw.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.sdw.policies.time.type = TimeBasedTriggeringPolicy
      appender.sdw.policies.time.interval = 1
      appender.sdw.policies.time.modulate = true
      appender.sdw.strategy.type = DefaultRolloverStrategy
      appender.sdw.strategy.delete.type = Delete
      appender.sdw.strategy.delete.basePath = ${application.log}
      appender.sdw.strategy.delete.maxDepth = 1
      appender.sdw.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.sdw.strategy.delete.ifLastModified.age = 30d

      loggers = ejdk,SeriesInResponse

      logger.ejdk.name = ejdk
      logger.ejdk.level = INFO
      logger.ejdk.additivity = false
      logger.ejdk.appenderRef.ejdk.ref = RollingFile
      appender.ejdk.type = RollingFile
      appender.ejdk.name = RollingFile
      appender.ejdk.fileName=G:/ApplicationLogs/sdw_internal_ejdk.log
      appender.ejdk.filePattern=G:/ApplicationLogs/sdw_internal_ejdk.log-%d{yyyy-
      MM-dd}.log.zip
      appender.ejdk.layout.type = PatternLayout
      appender.ejdk.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
      appender.ejdk.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.ejdk.policies.time.type = TimeBasedTriggeringPolicy
      appender.ejdk.policies.time.interval = 1
      appender.ejdk.policies.time.modulate = true
      appender.ejdk.strategy.type = DefaultRolloverStrategy
      appender.ejdk.strategy.delete.type = Delete
      appender.ejdk.strategy.delete.basePath = ${application.log}
      appender.ejdk.strategy.delete.maxDepth = 1
      appender.ejdk.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.ejdk.strategy.delete.ifLastModified.age = 30d

      logger.SeriesInResponse.name = SeriesInResponse
      logger.SeriesInResponse.level = INFO
      logger.SeriesInResponse.additivity = false
      logger.SeriesInResponse.appenderRef.SeriesInResponse.ref = RollingFile
      appender.SeriesInResponse.type = RollingFile
      appender.SeriesInResponse.name = RollingFile
      appender.SeriesInResponse.fileName=G:/ApplicationLogs/sdw_internal_series_responses.log
      appender.SeriesInResponse.filePattern=G:/ApplicationLogs/sdw_internal_series_responses.log-%d{yyyy-MM-dd}.log.zip
      appender.SeriesInResponse.layout.type = PatternLayout
      appender.SeriesInResponse.layout.pattern = %d{ISO8601} %m%n
      appender.SeriesInResponse.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.SeriesInResponse.policies.time.type = TimeBasedTriggeringPolicy
      appender.SeriesInResponse.policies.time.interval = 1
      appender.SeriesInResponse.policies.time.modulate = true
      appender.SeriesInResponse.strategy.type = DefaultRolloverStrategy
      appender.SeriesInResponse.strategy.delete.type = Delete
      appender.SeriesInResponse.strategy.delete.basePath = ${application.log}
      appender.SeriesInResponse.strategy.delete.maxDepth = 1
      appender.SeriesInResponse.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.SeriesInResponse.strategy.delete.ifLastModified.age = 30d









      share|improve this question
















      My log4j2 properties file looks like below-



      When I tried to access the appender by using the following code



      private static final Logger LOGGER = LogManager.getLogger("ejdk");
      LOGGER.info("test");


      It is logging the entry in SeriesInResponse appender not in the ejdk appender. My log4j2 has multiple custom appender. I need to use different appender in different class file and it should log the entry in the correct files.



      rootLogger.level = WARN
      appenders = sdw,ejdk,SeriesInResponse
      rootLogger.appenderRefs = sdw
      rootLogger.appenderRef.sdw.ref = RollingFile
      appender.sdw.type = RollingFile
      appender.sdw.name = RollingFile
      appender.sdw.fileName=G:/ApplicationLogs/sdw_internal_server.log
      appender.sdw.filePattern=G:/ApplicationLogs/sdw_internal_server-%d{yyyy-MM-
      dd}.log.zip
      appender.sdw.layout.type = PatternLayout
      appender.sdw.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
      appender.sdw.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.sdw.policies.time.type = TimeBasedTriggeringPolicy
      appender.sdw.policies.time.interval = 1
      appender.sdw.policies.time.modulate = true
      appender.sdw.strategy.type = DefaultRolloverStrategy
      appender.sdw.strategy.delete.type = Delete
      appender.sdw.strategy.delete.basePath = ${application.log}
      appender.sdw.strategy.delete.maxDepth = 1
      appender.sdw.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.sdw.strategy.delete.ifLastModified.age = 30d

      loggers = ejdk,SeriesInResponse

      logger.ejdk.name = ejdk
      logger.ejdk.level = INFO
      logger.ejdk.additivity = false
      logger.ejdk.appenderRef.ejdk.ref = RollingFile
      appender.ejdk.type = RollingFile
      appender.ejdk.name = RollingFile
      appender.ejdk.fileName=G:/ApplicationLogs/sdw_internal_ejdk.log
      appender.ejdk.filePattern=G:/ApplicationLogs/sdw_internal_ejdk.log-%d{yyyy-
      MM-dd}.log.zip
      appender.ejdk.layout.type = PatternLayout
      appender.ejdk.layout.pattern = %d{ISO8601} %-5p [%t] (%13F:%L) %3x - %m%n
      appender.ejdk.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.ejdk.policies.time.type = TimeBasedTriggeringPolicy
      appender.ejdk.policies.time.interval = 1
      appender.ejdk.policies.time.modulate = true
      appender.ejdk.strategy.type = DefaultRolloverStrategy
      appender.ejdk.strategy.delete.type = Delete
      appender.ejdk.strategy.delete.basePath = ${application.log}
      appender.ejdk.strategy.delete.maxDepth = 1
      appender.ejdk.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.ejdk.strategy.delete.ifLastModified.age = 30d

      logger.SeriesInResponse.name = SeriesInResponse
      logger.SeriesInResponse.level = INFO
      logger.SeriesInResponse.additivity = false
      logger.SeriesInResponse.appenderRef.SeriesInResponse.ref = RollingFile
      appender.SeriesInResponse.type = RollingFile
      appender.SeriesInResponse.name = RollingFile
      appender.SeriesInResponse.fileName=G:/ApplicationLogs/sdw_internal_series_responses.log
      appender.SeriesInResponse.filePattern=G:/ApplicationLogs/sdw_internal_series_responses.log-%d{yyyy-MM-dd}.log.zip
      appender.SeriesInResponse.layout.type = PatternLayout
      appender.SeriesInResponse.layout.pattern = %d{ISO8601} %m%n
      appender.SeriesInResponse.policies.type = Policies

      # Rotate log file each day and keep 60 days worth
      appender.SeriesInResponse.policies.time.type = TimeBasedTriggeringPolicy
      appender.SeriesInResponse.policies.time.interval = 1
      appender.SeriesInResponse.policies.time.modulate = true
      appender.SeriesInResponse.strategy.type = DefaultRolloverStrategy
      appender.SeriesInResponse.strategy.delete.type = Delete
      appender.SeriesInResponse.strategy.delete.basePath = ${application.log}
      appender.SeriesInResponse.strategy.delete.maxDepth = 1
      appender.SeriesInResponse.strategy.delete.ifLastModified.type = IfLastModified
      # Delete files older than 30 days
      appender.SeriesInResponse.strategy.delete.ifLastModified.age = 30d






      apache log4j log4j2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 15:08







      Subhajit Pal

















      asked Nov 14 '18 at 14:54









      Subhajit PalSubhajit Pal

      991111




      991111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You should use different names for the appenders.



          In your config everything is going to "RollingFile" appender.



          Change



          appender.ejdk.name = RollingFile



          to



          appender.ejdk.name = RollingFileEjdk



          and



          logger.ejdk.appenderRef.ejdk.ref = RollingFile



          to



          logger.ejdk.appenderRef.ejdk.ref = RollingFileEjdk



          Correct the other appanders and appenderRefs similarly.






          share|improve this answer

























            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%2f53303000%2flog4j2-issue-when-use-multiple-custom-rolling-file-appender%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You should use different names for the appenders.



            In your config everything is going to "RollingFile" appender.



            Change



            appender.ejdk.name = RollingFile



            to



            appender.ejdk.name = RollingFileEjdk



            and



            logger.ejdk.appenderRef.ejdk.ref = RollingFile



            to



            logger.ejdk.appenderRef.ejdk.ref = RollingFileEjdk



            Correct the other appanders and appenderRefs similarly.






            share|improve this answer






























              1














              You should use different names for the appenders.



              In your config everything is going to "RollingFile" appender.



              Change



              appender.ejdk.name = RollingFile



              to



              appender.ejdk.name = RollingFileEjdk



              and



              logger.ejdk.appenderRef.ejdk.ref = RollingFile



              to



              logger.ejdk.appenderRef.ejdk.ref = RollingFileEjdk



              Correct the other appanders and appenderRefs similarly.






              share|improve this answer




























                1












                1








                1







                You should use different names for the appenders.



                In your config everything is going to "RollingFile" appender.



                Change



                appender.ejdk.name = RollingFile



                to



                appender.ejdk.name = RollingFileEjdk



                and



                logger.ejdk.appenderRef.ejdk.ref = RollingFile



                to



                logger.ejdk.appenderRef.ejdk.ref = RollingFileEjdk



                Correct the other appanders and appenderRefs similarly.






                share|improve this answer















                You should use different names for the appenders.



                In your config everything is going to "RollingFile" appender.



                Change



                appender.ejdk.name = RollingFile



                to



                appender.ejdk.name = RollingFileEjdk



                and



                logger.ejdk.appenderRef.ejdk.ref = RollingFile



                to



                logger.ejdk.appenderRef.ejdk.ref = RollingFileEjdk



                Correct the other appanders and appenderRefs similarly.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 7:24

























                answered Nov 14 '18 at 16:07









                riskopriskop

                977823




                977823
































                    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%2f53303000%2flog4j2-issue-when-use-multiple-custom-rolling-file-appender%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

                    Bressuire

                    Vorschmack

                    Quarantine