Spring boot and Graylog

Graylog is a platform (free and enterprise) that is useful for log management of aggregated data. It is based on Elasticsearch, MongoDB and Scala.
It can display messages and histograms.

To send data to a graylog server through an HTTP appender with log4J2, i used the GELF layout with the following configuration :

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" monitorInterval="30">
	<Properties>
		<Property name="LOG_PATTERN">
			%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName}
			--- [%15.15t] %-40.40c{1.} : %m%n%ex
		</Property>
	</Properties>
	<Appenders>
		<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
			<PatternLayout pattern="${LOG_PATTERN}" />
		</Console>

        <!--  Appender for GRAYLOG -->     
		<Http name="Http" url="http://xxx.yyy.zz.aa/gelf" >		
			<GelfLayout host="localhostGraylog" compressionType="OFF" includeStacktrace="true">
				<KeyValuePair key="environment" value="myappGraylog" />
			</GelfLayout>
		</Http>
		
	</Appenders>

	<Loggers>
		<Logger name="com.celinio.app" level="debug"
			additivity="false">
			<AppenderRef ref="ConsoleAppender" />
 			<AppenderRef ref="Http" /> 
		</Logger>

		<!-- Spring Boot -->
		<Logger name="org.springframework.boot" level="debug"
			additivity="false">
		        <AppenderRef ref="ConsoleAppender" />
 			<AppenderRef ref="Http" /> 
		</Logger>

		<Logger name="org.hibernate" level="debug" additivity="false">
			<AppenderRef ref="ConsoleAppender" />
 			<AppenderRef ref="Http" /> 
		</Logger>

		<Root level="debug">
			<AppenderRef ref="ConsoleAppender" />
 			<AppenderRef ref="Http" /> 
		</Root>
	</Loggers>
</Configuration>

I had to use the latest version of log4j2 (2.11.2) and i also had to comment out the use of the Spring boot starter for log4j2 :

<properties>
        ...
    	<log4j.version>2.11.2</log4j.version>
</properties>
<dependencies>
        ...
	<!-- 
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-log4j2</artifactId>
	</dependency>
	 -->
	<dependency>
		<groupId>org.apache.logging.log4j</groupId>
		<artifactId>log4j-api</artifactId>	
		<version>${log4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.apache.logging.log4j</groupId>
		<artifactId>log4j-core</artifactId>
		<version>${log4j.version}</version>
	</dependency>
</dependencies>

Version of Spring boot : 1.5.21.RELEASE

[Tutorial] Log4J with Maven profiles

Here is a quick tutorial to get your hands dirty with the Log4j logging framework.
Log4j allows logging requests to print to multiple output destinations, also known as appenders.
There are several output destinations: console, files, sockets, emails …
First create a Maven project :
mvn archetype:generate
Choose archetype number 109 (quickstart)

Continue reading