Log4j

Send application logs to Observe with Log4j. For more about configuring and using Log4j, see its documentation here Log4j Documentation.

Requirements

To do this you will need the following information:

  • Your Observe Customer ID

  • Your Observe ingest token

  • Ability to restart your application

Configuring Log4j

  1. Open the log4j2.xml file for your application.

  2. Add the following Http appender to your log4j.xml file, inserting your Customer ID and ingest token into the value attribute of the Authorization node.

    <Appenders>
       <Http name="Observe" url="https://collect.observeinc.com/v1/http/log4j">
          <JsonLayout compact="true" eventEol="true" properties="true" />
          <Property name="Content-Type" value="application/json" />
          <Property name="Authorization" value="Bearer customer-id ingest-token" />
       </Http>
    </Appenders>
    
  3. Add an AppenderRef inside the AsyncRoot node for the Observe Http appender from the previous step.

    <AsyncRoot level="INFO">
        <AppenderRef ref="Observe" />
    </AsyncRoot>
    
  4. Restart the application to pick up the changes made to log4j2.xml.

Example Log4j Configurations

Below are some examples using the Http appender to send data to Observe.

Observe Only

Send log data to one destination, Observe, using the Http appender.

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Appenders>
   <Http name="Observe" url="https://collect.observeinc.com/v1/http/log4j">
      <JsonLayout compact="true" eventEol="true" properties="true" />
      <Property name="Content-Type" value="application/json" />
      <Property name="Authorization" value="Bearer customer-id ingest-token" />
   </Http>
</Appenders>
<Loggers>
   <AsyncLogger name="org.application.service.http" level="WARN"/>
   <AsyncLogger name="org.application.extension.http" level="WARN"/>
   <AsyncLogger name="org.application.runtime.core.internal.processor.LoggerMessageProcessor" level="INFO"/>
   <AsyncRoot level="INFO">
      <AppenderRef ref="Observe" />
   </AsyncRoot>
</Loggers>

Multiple Log Appenders

Use both the file appender and the Http appender to send logs to two destinations: a local file and Observe.

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
 <Appenders>
     <RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}web-service-consumer.log" 
              filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}web-service-consumer-%i.log">
         <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
         <SizeBasedTriggeringPolicy size="10 MB" />
         <DefaultRolloverStrategy max="10"/>
     </RollingFile>
     <Http name="Observe" url="https://collect.observeinc.com/v1/http/log4j">
      <JsonLayout compact="true" eventEol="true" properties="true" />
      <Property name="Content-Type" value="application/json" />
      <Property name="Authorization" value="Bearer customer-id ingest-token" />
   </Http>
 </Appenders>
 <Loggers>
   <!-- Http Logger shows wire traffic on DEBUG. -->
   <AsyncLogger name="org.application.service.http" level="WARN"/>
     <AsyncLogger name="org.application.extension.http" level="WARN"/>

     <!-- Mule classes -->        
     <AsyncLogger name="org.application" level="INFO"/>
     <AsyncLogger name="com.application" level="INFO"/>

     <AsyncRoot level="INFO">
         <AppenderRef ref="file" />
         <AppenderRef ref="Observe" />
   </AsyncRoot>
 </Loggers>
</Configuration>