Announcement Announcement Module
Collapse
No announcement yet.
Disable loggin for standalone Hello World! app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disable loggin for standalone Hello World! app

    Hello,
    I searched on forums but could not find an answer for this question, as all problems relate to apps running on web servers.

    I have the following bean.xml file:
    Code:
      
      <!-- headers ommited -->
      <bean id="bean1" class="Bean">
        <property name="say" value="Hello world!"/>
      </bean>
    And the following Bean.java file:
    Code:
    //import header ommited
    public class Bean {
      public Bean () {}
      private String say;
      public void setSay (String what) {this.say = what; }
      public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext ctx 
            = new ClassPathXmlApplicationContext("bean.xml"); 
        Bean b = ctx.getBean("bean1",Bean.class);
        System.out.println(b.say);
      }  
    }
    Running this program produces six lines of info logs - what should I do to turn them off?

    Best regards,
    zoom.

  • #2
    These logs could be coming from spring classes.

    Ensure that your logging framework will have error levels for classes which are spitting the logs.

    something like com.springfgramework.* - to have error level

    Comment


    • #3
      So what shoul I do? :-)

      sudhherk, thanks for your answer.
      Obviously the logs come from Spring framework but I did not ask for them.
      I tried to make the smallest Hello World app, only this libraries are in classpath:
      Code:
      commons-logging-1.1.1.jar
      org.springframework.asm-3.0.0.RELEASE.jar
      org.springframework.beans-3.0.0.RELEASE.jar
      org.springframework.context-3.0.0.RELEASE.jar
      org.springframework.core-3.0.0.RELEASE.jar
      org.springframework.expression-3.0.0.RELEASE.jar
      I tried to delete commons-logging-1.1.1.jar but then spring throws ClassNotFoundException.

      So what do I need to do to turn off logging?

      Comment


      • #4
        i mean to say its uses commons logging to log. Set the logging level to required level.

        http://commons.apache.org/logging/gu...l#Introduction
        [default is info]

        Comment


        • #5
          Adding to what Sudheer says,

          In your log4j.properties,

          just set
          Code:
          # Debug statements logged by Spring framework.
          log4j.category.org.springframework=<the level that you want to get printed eg: INFO,DEBUG>
          Priya
          More Java Programming Tips

          Comment


          • #6
            Still does not work ..

            sudheerk, priyavenkat thanks for your answers.
            In my simple Hello World! app I did not have a log4j.properties file so I created one.
            I did not know where to put it so I used the same folder where the sources are [I use eclipse so it got automatically copied to binary folder that is in classpath]

            My log4j.properties looks like this:
            Code:
            log4j.category.org.springframework=ERROR
            But still my Hello World! app produces six lines of INFO logs :-(
            Maybe it is because I do not use log4j in my tiny app?

            I also went with sudheerk's advice and read commons-logging doc and I created the following commons-logging.properties file
            Code:
            org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
            org.apache.commons.logging.simplelog.defaultlog=ERROR
            Amazingly spring log output got reduced from 6 lines to 3 all starting with [INFO] string

            so it's like 50% success...
            But I see it as 50% failure :-)
            Any more I ideas what should I do - all I have is a simpe Hello world! app

            Comment


            • #7
              here it is

              Hi Dude,

              am not sure how you have implemented log4j.

              here is the complete details of a sample implementation. This should get you through. Check this out

              How to use Log4j in Spring Projects: Sample

              Let me know if this works

              Thanks
              Priya

              Comment


              • #8
                It works, thanks a lot, but..

                It works -thanks [I easly managed to change ERROR output to console].
                It is a very nice tutorial that you wrote - now everyone can understand

                But as long as all I need to do is just turn logging off - this solutions seems somewhat ugly - I need to download another library to disable something. It seems a little like a workaround :-)

                But still you tutorial is very useful and thanks a lot!

                Comment

                Working...
                X