Announcement Announcement Module
Collapse
No announcement yet.
How to setup logging? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to setup logging?

    -Dlog4j.configuration jvm option didn't help

    Also I noticed strange thing - even if I specify import:
    org.apache.log4j;version="1.2.15", really used version is : lib/com.springsource.slf4j.org.apache.log4j-1.5.0.jar

    1. How to configure log4j?
    2. Is it possible to use platform logging capabilities from: com.springsource.platform.serviceability.* ?
    I'm confused that those bundles don't export anything..

    Olex

  • #2
    How to setup logging?

    Hi Olex,

    1. To configure trace levels both globally and on a per-application basis, check out the configuration chapter of the User Guide here:

    http://static.springsource.com/projects/s2ap/1.0.x/user-guide/html/ch06.html

    2. Yes, the S2AP automatically routes log statements on a per-application basis to the PLATFORM_HOME/serviceability/trace directory. For more information on application trace files, check out chapter 4 of the User Guide here:

    http://static.springsource.com/projects/s2ap/1.0.x/user-guide/html/ch04s02.html

    Best regards,

    Sam

    Comment


    • #3
      How to setup logging?

      So what is the proper way to do logging in your code in an application that runs on the SpringSource AP? Just try to use log4j as usual?

      Comment


      • #4
        How to setup logging?

        Hi Eric,

        > So what is the proper way to do logging in your code in an application
        > that runs on the SpringSource AP? Just try to use log4j as usual?

        Yes, that's correct: use log4j as your normally would. Note, however, that log levels are configured as described in the User Guide here:

        http://static.springsource.com/projects/s2ap/1.0.x/user-guide/html/ch04s02.html

        Regards,

        Sam

        Comment


        • #5
          How to setup logging?

          A common log4j file would look like:

          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

          <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

          <appender name="appender" class="org.apache.log4j.FileAppender">
          <param name="File" value="identity.log"/>
          <param name="Append" value="false"/>
          <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
          </layout>
          </appender>

          <category name="foo.bar">
          <priority value="debug"/>
          <appender-ref ref="appender"/>
          </category>

          <root>
          <priority value ="debug"/>
          <appender-ref ref="appender"/>
          </root>

          The log4j.xml file is deployed with my web bundle and located in the WEB-INF/classes.

          The problem is that the identity.log is not being created.

          Any idea why ???

          Comment


          • #6
            How to setup logging?

            Hi Thorsten,

            When I said "use log4j as your normally would", I may have been a little vague. What I meant is that you will programatically use log4j the same as you normally would, in terms of obtaining a logger in your classes, etc.; however, the configuration for log4j on the Platform is different in that it is global.

            > The problem is that the identity.log is not being created.

            That's correct. Your log4j log output is being routed to a file such as $PLATFORM_HOME/serviceability/trace/com.myapp-1/trace.log. In addition, your log4j.xml file will not be processed on the S2AP. Instead, you will need to configure this globally as explained in the "Per-application trace" section of the User Guide:

            SpringSource Application Platform uses SLF4J-based implementations of both Commons Logging and Log4J to route output generated by applications using those APIs to its trace files. In addition to appending such output to the global trace.log it will also append it to an application-specific trace file.

            SpringSource Application Platform writes application-specific trace to a file in a subdirectory of the configured trace directory. As described above this directory is, by default, $PLATFORM_HOME/serviceability/trace. The subdirectory's name is of the form <application-name>-<version>. So, for example, an application named com.myapp at version 1 will write its trace to a file in $PLATFORM_HOME/serviceability/trace/com.myapp-1/.

            Regards,

            Sam

            Comment


            • #7
              I was trying to use per-application tracing with apache commons logging. Each of my applications has their own folder and respective trace file under the serviceability/trace folder. What does not work is that the log statements from the application do not go to the per-application trace files.
              They show up on the console in Eclipse when I run it from there as well as in the global trace.log file. Do I need to do anything special to get the log statements to appear in the per application trace.log files?

              Comment


              • #8
                To make use of dm Server's per-application tracing, you need to make use of the SLF4J version of commons logging so that your calls via the commons logging API are passed into dm Server's serviceability component.

                How are you importing the commons logging package(s)? I'd recommend using Import-Package as this should ensure that you get wired to the SLF4J-based version of the packages.

                Comment


                • #9
                  I am using the following code to import and use apache commons logging -

                  import org.apache.commons.logging.Log;
                  import org.apache.commons.logging.LogFactory;

                  private static final Log log = LogFactory.getLog(foo.class);

                  Subsequently in a method -

                  log.error("Retrieving descendents....>");

                  org.apache.commons.logging is also added as a dependency to my application.

                  Comment


                  • #10
                    Sorry, I should have been clearer in my question above. I'm interested to know how you're importing the commons logging package in your manifest, rather than in your code. Could you post the manifest of the bundle in which you're using Commons Logging, please?

                    Comment


                    • #11
                      This is how the manifest looks -

                      Manifest-Version: 1.0
                      Export-Package: com.inventoryService;version="0";uses:= "com.vim", com.inventoryService.impl;version="0";uses:="com.v im, com.vim.managedobject,com.vim.service,com.inventor yService"
                      Bundle-Vendor: foo
                      Bundle-Classpath: .
                      Application-TraceLevels: *=error
                      Bundle-Version: 1.0.0
                      Bundle-Name: inventoryService
                      Bundle-ManifestVersion: 2
                      Import-Package: com.core,com.vim, com.vim.managedobject, com.vim.service, com.vim.service.version5, com.vimSecurity, com.vimService, org.apache.commons.logging, org.springframework.security, org.springframework.security.context
                      Bundle-SymbolicName: com.ngc.inventoryService

                      Comment


                      • #12
                        Hey Andy, any on what could be wrong?

                        Comment


                        • #13
                          Your manifest looks good as you're using Import-Package to pull in commons logging.

                          How are you driving the code that contains to logging calls? dm Server is aware of a number of entry points into the server, and at these entry points it sets up some thread-based context that's used by the per-application trace routing. The entry points of which dm Server is aware include requests received by Tomcat, and during application deployment.

                          One entry point that is not covered is any logging that triggered as a result of using the telnet console. E.g. if you stop or start a bundle using the console and it performs some logging in its activator, this logging will not be routed to the per-application trace file as dm Server doesn't have an opportunity to set up the appropriate context.

                          Comment


                          • #14
                            Originally posted by Andy Wilkinson View Post
                            Your manifest looks good as you're using Import-Package to pull in commons logging.

                            How are you driving the code that contains to logging calls? dm Server is aware of a number of entry points into the server, and at these entry points it sets up some thread-based context that's used by the per-application trace routing. The entry points of which dm Server is aware include requests received by Tomcat, and during application deployment.
                            I am not clear on your question, can you clarify what code do you want me to look into?

                            Comment


                            • #15
                              How to use slf4j properly?

                              In my application I use slf4j everywhere.

                              I did not know how to properly configure the logging in Spring DM server, so I created my own workaround which worked fine in 1.0.2.RELEASE. But now it does not work with the latest build.

                              Here is my workaround. I created a small bundle that contained its own slf4j-api-1.5.8.jar, and exported org.slf4j;version="1.5.8". It also contained slf4j-log4j12-1.5.8.jar and log4j-1.2.14.jar. In a simple java code, upon startup, it reads the log4j.properties from known location and configures log4j. It also provides a dummy service which other bundles consume, to make sure that configuration happens before anybody uses it.
                              So other bundles import org.slf4j;version="1.5.8", and request that dummy service. Everything is OK in 1.0.2.RELEASE, but not in 2.0.0.CI-B350 (the bundle deployment gets stuck, and the admin console get the server error - is this a bug by itself?)

                              I understand that there should be a better way, because slf4j and log4j are already available in core bundles, so my question is: how should it be configured? What my bundles have to import, and where do I put log4j.properties?

                              Comment

                              Working...
                              X