Local json and Elk integration



Mule Anypoint configuration

Notes

input {
tcp {
port => 5000
type => syslog
}
}

….other config….

I fixed this issue by config logstash as this:

input {
beats {
port => 5000
type => syslog
}
}

….other config….

Just replace “tcp” or “udp”

Configure Log4j2 with an JDBC Appender in Mule

The steps for implement this solution to any project are

  • Add sqljdbc4.jar to buildpath.
  • Add the ConnectionFactory.java to your project.
  • The ConnectionFactory class is very simple:
    private static interface Singleton {
      final ConnectionFactory INSTANCE = new ConnectionFactory();
    }
     
    private final DataSource dataSource;
     
    private ConnectionFactory() {
      SQLServerDataSource ds = new SQLServerDataSource();
      ds.setServerName(System.getProperty("url"));
      ds.setPortNumber(Integer.parseInt(System.getProperty("dbPort")));
      ds.setDatabaseName(System.getProperty("databaseName"));
      ds.setUser(System.getProperty("user"));
      ds.setPassword(System.getProperty("password"));
      this.dataSource = ds;
    }
     
    public static Connection getDatabaseConnection() throws SQLException {
       return Singleton.INSTANCE.dataSource.getConnection();
    }

Modify log4j.xml with you prefered database/table configuration and point to connection factory java class and method.

<Jdbc name="databaseAppender" tableName="dsLogEntry" ignoreExceptions="false" >
  <ConnectionFactory class="net.example.db.ConnectionFactory" method="getDatabaseConnection" />
  <Column name="eventDate" isEventTimestamp="true" />
  <Column name="literalColumn" literal="'Literal Value of Data Source'" />
  <Column name="level" pattern="%level" />
  <Column name="logger" pattern="%logger" />
  <Column name="message" pattern="%message" isUnicode="false" />
  <Column name="exception" pattern="%ex{full}" />
</Jdbc>

Also the appender ref in the log4j.xml must be pointing to the jdbc appender.

 
<AppenderRef ref="databaseAppender" level="INFO"/>
Create the logging table in the running database e.g:
CREATE TABLE [dbo].[dsLogEntry](
  [id] [numeric](18, 0) NOT NULL,
  [eventDate] [datetime] NULL,
  [literalColumn] [varchar](5000) NULL,
  [level] [varchar](5000) NULL,
  [logger] [varchar](5000) NULL,
  [message] [varchar](5000) NULL,
  [exception] [varchar](5000) NULL
) ON [PRIMARY] 

The last step is configure the VM arguments in the Mule Application Server and run it. For studio Execute the application with the next parameters for the JVM:

-Durl=localhost -DdbPort=1433 -DdatabaseName=datatest -Duser=testuser -Dpassword=test123

For Standalone Follow the next guideline How-can-I-set-Mule-and-Java-system-properties-at-startup to configure the next parameters

url=localhost 
dbPort=1433 
databaseName=datatest 
user=testuser 
password=test123
 
mule_logging.txt · Last modified: 2019/02/08 05:50 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd