2 Replies Latest reply on Apr 26, 2013 9:36 AM by Zoltan Penzeli

    How to configure custom logger appender (Graylog2 - GELF4j)

    Edison Melo Newbie

      Hi

       

      What is the best aproach to use GELF4j as an appender in JBOSS 7.1.1 ? Has anyone have a working configuration that can share ?

        • 1. Re: How to configure custom logger appender (Graylog2 - GELF4j)
          Edison Melo Newbie

          I will response my own question.  Checking the code, the project has a JDK logger handler, but spect a property file for configuration, and I couldn't find a way to pass the config parameters.  Then I found another project.  The handler in this project has the public methods needed to use it as a custom handler.  Is working right now using this config:

           

          {code:xml}<custom-handler name="GREYLOG2" class="org.graylog2.logging.GelfHandler" module="org.graylog2">

              <properties>

                  <property name="graylogHost" value="192.168.1.120"/>

                  <property name="extractStacktrace" value="true"/>

                  <property name="addExtendedInformation" value="true"/>

                  <property name="Facility" value="user"/>

                  <property name="FacilityPrinting" value="true"/>

                  <property name="Threshold" value="INFO"/>

              </properties>

          </custom-handler>{code}

          • 2. Re: How to configure custom logger appender (Graylog2 - GELF4j)
            Zoltan Penzeli Newbie

            Hi,

             

            Thanks for your post about Greylog / GELF4j. Based on this and some Google-ing, I was also able to "force" JBoss to use the Gelf handler created by "t0xa".

            Because the process wasn't too straightforward, and the result is still not perfect, I would like to summarise what I have done, so people with less experience would be able to achieve what I did - and more experienced people might be able to help with the questions I collected...

             

            So, here it is how I managed to do it:

             

            1. First, add required modules to JBoss

             

            • fetch the latest Gelf version from GitHub: https://github.com/t0xa/gelfj
            • compile with "mvn package" (at the time of this post, there is a sporadic bug, which prevents compiling "sometimes". Recompile multiple times to succeed.)
            • copy the .jar file from gelfj/target/ directory to/as {jboss}/modules/org/graylog2/logging/main/gelfj.jar (create directories as needed)
            • create the following module.xml file in the same directory:

             

             

            <module xmlns="urn:jboss:module:1.1" name="org.graylog2.logging">  
               <resources>  
                 <resource-root path="gelfj.jar"/>  
               </resources>  
               <dependencies>  
                 <module name="json-simple"/>  
               </dependencies>  
             </module>  
            
            

             

             

            <module xmlns="urn:jboss:module:1.1" name="json-simple">  
               <resources>  
                 <resource-root path="json-simple.jar"/>  
               </resources>  
               <dependencies>  
               </dependencies>  
             </module>
            
            

             

            2. Open your relevant "standalone.xml" file and go to <subsystem xmlns="urn:jboss:domain:logging:1.1">

             

            • Add the following custom-handler right under this "subsystem":

             

             

                        <custom-handler name="GREYLOG2" class="org.graylog2.logging.GelfHandler" module="org.graylog2.logging">
                            <level name="INFO"/> <!-- or what you want... -->
                            <properties>
                                <property name="graylogHost" value="YOUR.IP.HERE"/>
                                <property name="extractStacktrace" value="true"/>
                                <property name="facility" value="JBoss"/>
                            </properties>
                        </custom-handler>
            
            

             

            (Note: Other parameters (FacilityPrinting, Threshold) listed by Edison above are not picked up by the handler, because they have no setters and practically they are not used by GelfHandler at all.)

             

            • Add this handler to the list of handlers in root-logger:

             

             

                        <root-logger>
                            <level name="..."/>
                            <handlers>
                                  <!-- other handlers here -->
                                  <handler name="GREYLOG2"/>
                            </handlers>
                        </root-logger>
            
            

             

            • Restart JBoss and check startup logs. You shouldn't see any WARN or worse about Graylog/GelfHandler and logs should go directly to Graylog server.

             

            (If you see %s, %d, etc. in the logs in Graylog, it means, my pull request about String.format type parameters is not yet approved. <- This is now merged. Use https://github.com/zpenzeli/gelfj repo to compile a new version, if needed.)

             

            So now, about the problems:

            • on Graylog side, all of the logs are indicated as "Debug". This might come from the fact how JBoss uses its Appenders, because GelfHandler uses java.util.logging and the log levels are different. But I'm not really sure... I fixed this by adding more proper log level handling to GelfHandler in the gelfj library. Also can be found in my forked repo, until merged to main (see link above).
            • I still can see some %s type logs, which might come from some invalid log entry coming from some of the components in the system

             

            Message was edited by: Zoltan Penzeli - reason: solved log level indicator issue.