Permalink
Browse files

Initial commit

  • Loading branch information...
fpaparoni committed Feb 28, 2017
0 parents commit 59fb3920b04cec570fc151186d7f4ef8a70a89d4
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
@@ -0,0 +1 @@
/target/
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>logstashtest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,73 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.javastaff.elk</groupId>
<artifactId>logstashtest</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>LogstastTEst</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.22</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>log4j</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>net.logstash.log4j</groupId>
<artifactId>jsonevent-layout</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>logback</id>
<dependencies>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.8</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.6</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
@@ -0,0 +1,23 @@
package com.javastaff.elk.logstashtest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class App {
private static final Logger LOG = LoggerFactory.getLogger(App.class);

public static void main(String[] args) throws InterruptedException {
MDC.put("producer", "pippo");
while(true) {
LOG.info("Ciao");
try {
args[1].equals("ops");
}
catch (Exception e) {
LOG.error(e.toString());
}
Thread.currentThread().sleep(1333);
}
}
}
@@ -0,0 +1,37 @@
log4j.rootLogger=DEBUG,console

#Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n

#Main Log Appender
log4j.appender.mainLogAppender=org.apache.log4j.RollingFileAppender
log4j.appender.mainLogAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.mainLogAppender.Threshold=INFO
log4j.appender.mainLogAppender.File=prova.log
log4j.appender.mainLogAppender.Append=true
log4j.appender.mainLogAppender.MaxFileSize=5000KB
log4j.appender.mainLogAppender.MaxBackupIndex=10
log4j.appender.mainLogAppender.layout.ConversionPattern=%d{DATE} %-5p [%-15c{1}]: %m%n

#JSON appender
log4j.appender.json=org.apache.log4j.DailyRollingFileAppender
log4j.appender.json.File=app.log
log4j.appender.json.DatePattern=.yyyy-MM-dd
log4j.appender.json.layout=net.logstash.log4j.JSONEventLayoutV1
log4j.appender.json.layout.UserFields=application:logstashtest,environment:dev

#TCP appender
log4j.appender.tcp=org.apache.log4j.net.SocketAppender
log4j.appender.tcp.Port=3456
log4j.appender.tcp.RemoteHost=localhost
log4j.appender.tcp.ReconnectionDelay=10000
log4j.appender.tcp.Application=logstashtest

#Custom assignments
log4j.logger.com.javastaff.elk=DEBUG,mainLogAppender,json,tcp


#Disable additivity
log4j.additivity.mainLog=false
@@ -0,0 +1,20 @@
<configuration>
<property name="LOG_PATH" value="app.log" />
<appender name="jsonAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}</File>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<maxIndex>1</maxIndex>
<fileNamePattern>${LOG_PATH}.%i</fileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>1MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="jsonLogger" additivity="false" level="DEBUG">
<appender-ref ref="jsonAppender"/>
</logger>
<root level="INFO">
<appender-ref ref="jsonAppender"/>
</root>
</configuration>

0 comments on commit 59fb392

Please sign in to comment.