Pages

Subscribe:

Ads 468x60px

Thursday, March 17, 2016

How to Enable Asynchronous Logging with C5

In this post we are going to explore on how to enable asynchronous logging on C5 based servers. More on asynchronous logging can be found here.

1. Copy the disrupter dependency to the /osgi/plugins folder. You can get the disrupter OSGi bundle from here.
2. Edit launch.properties the /bin/bootstrap/org.wso2.carbon.launcher-5.1.0.jar and add the disrupter jar to the initial bundles list.
carbon.initial.osgi.bundles=\
  file\:plugins/org.eclipse.osgi.services_3.4.0.v20140312-2051.jar@1\:true,\
  file\:plugins/disruptor-3.2.0.jar@2\:true,\
  file\:plugins/org.ops4j.pax.logging.pax-logging-api_1.8.4.jar@2\:true,\
  file\:plugins/org.ops4j.pax.logging.pax-logging-log4j2_1.8.4.jar@2\:true,\
  file\:plugins/org.eclipse.equinox.simpleconfigurator_1.1.0.v20131217-1203.jar@3\:true

3. Set the org.ops4j.pax.logging.log4j2.async to true in the pax logging parameters.

4. Add the async loggers to the log4j2.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<Configuration>
    <Appenders>
 <RandomAccessFile name="RandomAccessFile" fileName="${sys:carbon.home}/logs/carbon.log" immediateFlush="false" append="false">
        <PatternLayout>
          <Pattern>[%d] %5p {%c} - %m%ex%n</Pattern>
        </PatternLayout>
     </RandomAccessFile>
        <Console name="CARBON_CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d] %5p {%c} - %m%ex%n"/>
        </Console>
        
    </Appenders>
    <Loggers>

 <AsyncLogger name="com.foo.Bar" level="trace" includeLocation="true">
      <AppenderRef ref="RandomAccessFile"/>
    </AsyncLogger>

        <Root level="debug">
     <AppenderRef ref="RandomAccessFile"/>
            <AppenderRef ref="CARBON_CONSOLE"/>
        </Root>
    </Loggers>
</Configuration>

That's it now you have enabled the asynchronous logging with C5.