Logging is performed via Log4J 2.
By default MySQLSync will log ALL events into the System console (which would be the web server System.out).
Customizing logging
Elasticsearch
AWS CloudWatch
Apache Kafka
Customizing logging
In order to customize logging we have to create a custom Log4J configuration file. Below is a example of such config file; lets suppose it is located in c:\temp\log4j-mysqlsync.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-config-2.xsd">
<Appenders>
<Console name="CONSOLE">
<PatternLayout pattern="%p - %m%n"/>
</Console>
<File name="DEBUG_LOG" fileName="c:/temp/debug.log">
<PatternLayout pattern="%d [%t] %p %c - %m%n"/>
</File>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="CONSOLE" level="WARN"/>
</Root>
<Logger name="com.mysqlsync" level="DEBUG">
<AppenderRef ref="DEBUG_LOG"/>
<AppenderRef ref="CONSOLE"/>
</Logger>
</Loggers>
</Configuration>
The above log4j configuration will print all INFO (and WARN, ERROR, FATAL) messages into the system console and debug (and INFO, WARN, ERROR, FATAL) messages with source com.mysqlsync into a file c:/temp/debug.log
Once we have created a custom Log4j configuration file for the mysqlsync.war application, we can specify it via a mysqlsync-log4j-config-file context variable. For example if MySQLSync is deployed in a Tomcat application server, we can specify the mysqlsync-log4j-config-file context variable inside Tomcat/conf/context.xml like
<Context>
<Environment name="mysqlsync-log4j-config-file"
value="c:\temp\log4j-conf.xml"
type="java.lang.String"
override="false"/>
</Context>
After specifying the location of our custom Log4J configuration file and restarting the Java web server containing mysqlsync.war the new debug logging will take effect.
Integration with Elasticsearch
Log4J contains a broad range of appenders, which we can utilize in order to store debug and error messages which can be inspected with Monitoring tools afterwards. For example it can even log events into Elasticsearch.
Logging to AWS CloudWatch
We can use the Log4J CloudWatch appender to store the logging data in AWS CloudWatch.
Logging to Apache Kafka
Apache Kafka is supported out of the box from Log4j2.