log4j Databse apender does not work properly











up vote
-1
down vote

favorite












My log4j.properties file look like



log4j.rootLogger = ERROR,sql, Appender1

log4j.logger.com.endeca=ERROR
log4j.logger.com.endeca.itl.web.metrics=ERROR

log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.sql.URL=jdbc:mysql://192.168.70.39:3306/cortex_mcss_ip
log4j.appender.sql.driver=com.mysql.jdbc.Driver
log4j.appender.sql.user=root
log4j.appender.sql.password=123456
log4j.appender.sql.sql=INSERT INTO errorlog(Level,Msg,CreatedDate) VALUES ('%p','%m',now())
log4j.appender.sql.layout=org.apache.log4j.PatternLayout


log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=D:/Logs/Log4jWebDemo.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n


when error occurs it works fine on console and file appender,but does not insert into databse anything ?



Note : databse parameters are 100% accurate in every corner.



Any one please help me to solve this...plz...










share|improve this question


























    up vote
    -1
    down vote

    favorite












    My log4j.properties file look like



    log4j.rootLogger = ERROR,sql, Appender1

    log4j.logger.com.endeca=ERROR
    log4j.logger.com.endeca.itl.web.metrics=ERROR

    log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
    log4j.appender.sql.URL=jdbc:mysql://192.168.70.39:3306/cortex_mcss_ip
    log4j.appender.sql.driver=com.mysql.jdbc.Driver
    log4j.appender.sql.user=root
    log4j.appender.sql.password=123456
    log4j.appender.sql.sql=INSERT INTO errorlog(Level,Msg,CreatedDate) VALUES ('%p','%m',now())
    log4j.appender.sql.layout=org.apache.log4j.PatternLayout


    log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
    log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
    log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

    log4j.appender.Appender2=org.apache.log4j.FileAppender
    log4j.appender.Appender2.File=D:/Logs/Log4jWebDemo.log
    log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
    log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n


    when error occurs it works fine on console and file appender,but does not insert into databse anything ?



    Note : databse parameters are 100% accurate in every corner.



    Any one please help me to solve this...plz...










    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      My log4j.properties file look like



      log4j.rootLogger = ERROR,sql, Appender1

      log4j.logger.com.endeca=ERROR
      log4j.logger.com.endeca.itl.web.metrics=ERROR

      log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
      log4j.appender.sql.URL=jdbc:mysql://192.168.70.39:3306/cortex_mcss_ip
      log4j.appender.sql.driver=com.mysql.jdbc.Driver
      log4j.appender.sql.user=root
      log4j.appender.sql.password=123456
      log4j.appender.sql.sql=INSERT INTO errorlog(Level,Msg,CreatedDate) VALUES ('%p','%m',now())
      log4j.appender.sql.layout=org.apache.log4j.PatternLayout


      log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
      log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
      log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

      log4j.appender.Appender2=org.apache.log4j.FileAppender
      log4j.appender.Appender2.File=D:/Logs/Log4jWebDemo.log
      log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
      log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n


      when error occurs it works fine on console and file appender,but does not insert into databse anything ?



      Note : databse parameters are 100% accurate in every corner.



      Any one please help me to solve this...plz...










      share|improve this question













      My log4j.properties file look like



      log4j.rootLogger = ERROR,sql, Appender1

      log4j.logger.com.endeca=ERROR
      log4j.logger.com.endeca.itl.web.metrics=ERROR

      log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
      log4j.appender.sql.URL=jdbc:mysql://192.168.70.39:3306/cortex_mcss_ip
      log4j.appender.sql.driver=com.mysql.jdbc.Driver
      log4j.appender.sql.user=root
      log4j.appender.sql.password=123456
      log4j.appender.sql.sql=INSERT INTO errorlog(Level,Msg,CreatedDate) VALUES ('%p','%m',now())
      log4j.appender.sql.layout=org.apache.log4j.PatternLayout


      log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
      log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
      log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

      log4j.appender.Appender2=org.apache.log4j.FileAppender
      log4j.appender.Appender2.File=D:/Logs/Log4jWebDemo.log
      log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
      log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n


      when error occurs it works fine on console and file appender,but does not insert into databse anything ?



      Note : databse parameters are 100% accurate in every corner.



      Any one please help me to solve this...plz...







      java logging log4j






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 4:52









      rahuLrajaN

      64




      64
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          To Directly address your question:
          you should debug this appender to see what happens.




          1. Make sure that DB driver (mysql in this case) appears in the classpath of the application.


          2. Make sure that the table / schema exist, because this appender by its own does not create a schema for you


          3. Note that it has a "bufferSize" parameter, so only if the non-stored message count exceeds the buffer, the actual DB request gets performed.


          4. Place a breakpoint on org.apache.log4j.jdbc.JDBCAppender#execute and see how it really executes



          Overall observation/side notes, not directly related to your answer but still can be valuable.
          This appender is really outdated and is not a really good solution for modern production applications (unless you have a very small number of logs).



          This appender doesn't use batch inserts supported by probably all modern RDBMSs.
          This appender doesn't user prepare statements.



          All-in-all storing logs in RDBMS doesn't really make sense nowadays, logs are meant to be read and analyzed, and RDBMS doesn't offer really handy tools for this (both visual and from the maintenance standpoint: how do delete obsolete messages? Bulk DELETE is very expensive, partitioning? Retention Policies for records are not really supported in many RDBMSs...



          So, a much more modern approach is using tools like ElasticSearch + Kibana (+ some log shipper) or even streaming logs to the cloud (like Logz.io)






          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',
            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%2f53201735%2flog4j-databse-apender-does-not-work-properly%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








            up vote
            0
            down vote



            accepted










            To Directly address your question:
            you should debug this appender to see what happens.




            1. Make sure that DB driver (mysql in this case) appears in the classpath of the application.


            2. Make sure that the table / schema exist, because this appender by its own does not create a schema for you


            3. Note that it has a "bufferSize" parameter, so only if the non-stored message count exceeds the buffer, the actual DB request gets performed.


            4. Place a breakpoint on org.apache.log4j.jdbc.JDBCAppender#execute and see how it really executes



            Overall observation/side notes, not directly related to your answer but still can be valuable.
            This appender is really outdated and is not a really good solution for modern production applications (unless you have a very small number of logs).



            This appender doesn't use batch inserts supported by probably all modern RDBMSs.
            This appender doesn't user prepare statements.



            All-in-all storing logs in RDBMS doesn't really make sense nowadays, logs are meant to be read and analyzed, and RDBMS doesn't offer really handy tools for this (both visual and from the maintenance standpoint: how do delete obsolete messages? Bulk DELETE is very expensive, partitioning? Retention Policies for records are not really supported in many RDBMSs...



            So, a much more modern approach is using tools like ElasticSearch + Kibana (+ some log shipper) or even streaming logs to the cloud (like Logz.io)






            share|improve this answer

























              up vote
              0
              down vote



              accepted










              To Directly address your question:
              you should debug this appender to see what happens.




              1. Make sure that DB driver (mysql in this case) appears in the classpath of the application.


              2. Make sure that the table / schema exist, because this appender by its own does not create a schema for you


              3. Note that it has a "bufferSize" parameter, so only if the non-stored message count exceeds the buffer, the actual DB request gets performed.


              4. Place a breakpoint on org.apache.log4j.jdbc.JDBCAppender#execute and see how it really executes



              Overall observation/side notes, not directly related to your answer but still can be valuable.
              This appender is really outdated and is not a really good solution for modern production applications (unless you have a very small number of logs).



              This appender doesn't use batch inserts supported by probably all modern RDBMSs.
              This appender doesn't user prepare statements.



              All-in-all storing logs in RDBMS doesn't really make sense nowadays, logs are meant to be read and analyzed, and RDBMS doesn't offer really handy tools for this (both visual and from the maintenance standpoint: how do delete obsolete messages? Bulk DELETE is very expensive, partitioning? Retention Policies for records are not really supported in many RDBMSs...



              So, a much more modern approach is using tools like ElasticSearch + Kibana (+ some log shipper) or even streaming logs to the cloud (like Logz.io)






              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                To Directly address your question:
                you should debug this appender to see what happens.




                1. Make sure that DB driver (mysql in this case) appears in the classpath of the application.


                2. Make sure that the table / schema exist, because this appender by its own does not create a schema for you


                3. Note that it has a "bufferSize" parameter, so only if the non-stored message count exceeds the buffer, the actual DB request gets performed.


                4. Place a breakpoint on org.apache.log4j.jdbc.JDBCAppender#execute and see how it really executes



                Overall observation/side notes, not directly related to your answer but still can be valuable.
                This appender is really outdated and is not a really good solution for modern production applications (unless you have a very small number of logs).



                This appender doesn't use batch inserts supported by probably all modern RDBMSs.
                This appender doesn't user prepare statements.



                All-in-all storing logs in RDBMS doesn't really make sense nowadays, logs are meant to be read and analyzed, and RDBMS doesn't offer really handy tools for this (both visual and from the maintenance standpoint: how do delete obsolete messages? Bulk DELETE is very expensive, partitioning? Retention Policies for records are not really supported in many RDBMSs...



                So, a much more modern approach is using tools like ElasticSearch + Kibana (+ some log shipper) or even streaming logs to the cloud (like Logz.io)






                share|improve this answer












                To Directly address your question:
                you should debug this appender to see what happens.




                1. Make sure that DB driver (mysql in this case) appears in the classpath of the application.


                2. Make sure that the table / schema exist, because this appender by its own does not create a schema for you


                3. Note that it has a "bufferSize" parameter, so only if the non-stored message count exceeds the buffer, the actual DB request gets performed.


                4. Place a breakpoint on org.apache.log4j.jdbc.JDBCAppender#execute and see how it really executes



                Overall observation/side notes, not directly related to your answer but still can be valuable.
                This appender is really outdated and is not a really good solution for modern production applications (unless you have a very small number of logs).



                This appender doesn't use batch inserts supported by probably all modern RDBMSs.
                This appender doesn't user prepare statements.



                All-in-all storing logs in RDBMS doesn't really make sense nowadays, logs are meant to be read and analyzed, and RDBMS doesn't offer really handy tools for this (both visual and from the maintenance standpoint: how do delete obsolete messages? Bulk DELETE is very expensive, partitioning? Retention Policies for records are not really supported in many RDBMSs...



                So, a much more modern approach is using tools like ElasticSearch + Kibana (+ some log shipper) or even streaming logs to the cloud (like Logz.io)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 5:09









                Mark Bramnik

                11.2k32445




                11.2k32445






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53201735%2flog4j-databse-apender-does-not-work-properly%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







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini