12 Replies Latest reply on Feb 15, 2013 7:34 AM by Johannes Bannhofer

    Trying out custom loggers

    Nicklas Karlsson Master

      I'm trying out the fresh custom logging in upstream master. I created a logger like

       

      public class DBLogger extends Handler

      {

                @Override

                public void publish(LogRecord record)

                {

                          System.out.println("logging");

                }

                @Override

                public void flush()

                {

                          System.out.println("flushing");

                }

       

       

                @Override

                public void close() throws SecurityException

                {

                          System.out.println("closing");

                }

      }

       

      and packaged it in a module like

       

      <?xml version="1.0" encoding="UTF-8"?>

      <module xmlns="urn:jboss:module:1.0" name="fi.affecto.dblogger">

          <resources>

              <resource-root path="DBLogger.jar"/>

          </resources>

       

       

          <dependencies>

              <module name="org.jboss.logging"/>

          </dependencies>

      </module>

       

      and modified standalone.xml logging subsystem with a

       

      <custom-logger name="DB" autoflush="true" module="fi.affecto.dblogger" class="fi.affecto.osti.fwkint.jbosslogging.DBLogger">

                <level name="INFO"/>

                <formatter>

                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                </formatter>

                <properties>

                          <property name="jndiName" value="java:jboss/datasources/OSTiDataSource"/>

                </properties>

      </custom-logger>

       

      but I get a parsing error in standalone.xml saying

       

      10:05:14,430 ERROR [stderr] Message: Unexpected element '{urn:jboss:domain:logging:1.1}custom-logger'

       

      which is strange, since

       

      jboss-as-logging_1_1.xsd has

       

      <xs:element name="custom-logger" type="customHandlerType" />

       

      and the logging subsystem uses

       

      <subsystem xmlns="urn:jboss:domain:logging:1.1">

       

      Theories?

       

      And another question, how are the parameters passed in (I'd like to set up a datasource when the logger starts)? I tried to look at the custom logger service startup but didn't see anything obvious and looking at the other logmanager handlers they operated mostly on hardcoded attributes and not on properties.

        • 1. Re: Trying out custom loggers
          jaikiran pai Master

          Can you please post the entire exception stacktrace and attach the standalone.xml?

          • 2. Re: Trying out custom loggers
            Nicklas Karlsson Master

            11:01:48,812 ERROR [stderr] Exception in thread "Controller Boot Thread" java.lang.RuntimeException: org.jboss.as.controller.persistence.ConfigurationPersistenceException: Failed to parse configuration

              11:01:48,813 ERROR [stderr]           at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:89)

              11:01:48,814 ERROR [stderr]           at java.lang.Thread.run(Thread.java:722)

              11:01:48,814 ERROR [stderr] Caused by: org.jboss.as.controller.persistence.ConfigurationPersistenceException: Failed to parse configuration

              11:01:48,815 ERROR [stderr]           at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:115)

              11:01:48,815 ERROR [stderr]           at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:104)

              11:01:48,816 ERROR [stderr]           at org.jboss.as.server.ServerService.boot(ServerService.java:193)

              11:01:48,816 ERROR [stderr]           at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:83)

              11:01:48,817 ERROR [stderr]           ... 1 more

              11:01:48,817 ERROR [stderr] Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[53,4]

            :01:48,817 ERROR [stderr] Message: Unexpected element '{urn:jboss:domain:logging:1.1}custom-logger'

              11:01:48,818 ERROR [stderr]           at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:98)

              11:01:48,818 ERROR [stderr]           at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69)

              11:01:48,819 ERROR [stderr]           at org.jboss.as.logging.LoggingSubsystemParser.readElement(LoggingSubsystemParser.java:162)

              11:01:48,819 ERROR [stderr]           at org.jboss.as.logging.LoggingSubsystemParser.readElement(LoggingSubsystemParser.java:88)

              11:01:48,820 ERROR [stderr]           at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:100)

              11:01:48,820 ERROR [stderr]           at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69)

              11:01:48,820 ERROR [stderr]           at org.jboss.as.controller.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:311)

              11:01:48,821 ERROR [stderr]           at org.jboss.as.controller.parsing.StandaloneXml.readServerElement(StandaloneXml.java:163)

              11:01:48,821 ERROR [stderr]           at org.jboss.as.controller.parsing.StandaloneXml.readElement(StandaloneXml.java:91)

              11:01:48,822 ERROR [stderr]           at org.jboss.as.controller.parsing.StandaloneXml.readElement(StandaloneXml.java:79)

              11:01:48,822 ERROR [stderr]           at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:100)

              11:01:48,823 ERROR [stderr]           at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:59)

              11:01:48,823 ERROR [stderr]           at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:107)

              11:01:48,824 ERROR [stderr]           ... 4 more

             

             

            BTW, is it so that the configuration persister nukes any comments in the XML file? I'm sure I commented it out at one point but it was gone later...

            • 3. Re: Trying out custom loggers
              James Perkins Master

              We currently aren't supporting properties yet. It is something we're looking into though. I'm wondering if you removed the <properties /> tag if it would work. The autoflush attribute is not supported either since the java.util.logging.Handler doesn't have an option for it. Maybe we should have written a wrapper to support it, but we haven't so far.

               

              Try removing the autoflush attribute and the properties to see if it works.

               

              Thanks,

              James R. Perkins

              • 5. Re: Trying out custom loggers
                James Perkins Master

                The issue is now fixed and the proper tag name is in the schema.

                 

                --

                James R. Perkins

                • 6. Re: Trying out custom loggers
                  Nicklas Karlsson Master

                  All right, now I get my custom handler registered and I see that the properties are being set but when I add it to the root logger and it get's hit it goes wild and spit out the "logging" until it croaks. Theories?

                  • 7. Retaining XML comments in domain configuration file
                    Johannes Bannhofer Newbie

                    Hi All,

                     

                    is there a solution for keeping comments in the standalone.xml?

                     

                    cheers

                     

                    BTW, is it so that the configuration persister nukes any comments in the XML file? I'm sure I commented it out at one point but it was gone later...

                    • 8. Re: Trying out custom loggers
                      Nicklas Karlsson Master

                      What AS version are you on? I thought that got fixed at some point...

                      • 9. Re: Trying out custom loggers
                        Johannes Bannhofer Newbie

                        we are using 7.1.1, if it is fixed it would be a reason for upgrating, if you have further informations would be greate, otherwhise will check it myself, thanks

                        • 11. Re: Trying out custom loggers
                          Nicklas Karlsson Master

                          Ah, apparently wishful thinking from my part (since I recall the JIRA was ancient). And marked "Open To Community" which means "Open Sourced to Silence" ;-)

                          • 12. Re: Trying out custom loggers
                            Johannes Bannhofer Newbie

                            Thanks for the information guys