Commit 8bffc2ee authored by Marcel Siegrist's avatar Marcel Siegrist

logging integrated (only console at the moment)...

parent 00c6582d
......@@ -17,6 +17,10 @@
<junit.version>4.11</junit.version>
<org.apache.httpclient.version>4.4-alpha1</org.apache.httpclient.version>
<org.apache.commons-io.version>2.4</org.apache.commons-io.version>
<!-- logger versions -->
<slf4j.version>1.7.7</slf4j.version>
<log4j2.version>2.1</log4j2.version>
</properties>
<dependencies>
......@@ -38,11 +42,32 @@
<version>${jodatime.version}</version>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>${junit.version}</scope>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
......
......@@ -7,6 +7,8 @@ import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
......@@ -34,6 +36,8 @@ import java.util.Properties;
public class App
{
private static Logger logger = LoggerFactory.getLogger( App.class );
private static final int CHECK_INTERVAL = 60000;
private static final String DEFAULT_PROPERTIES_FILE = "backslack.properties";
private static final String DEFAULT_WATCH_DIRECTORY = "./";
......@@ -54,8 +58,8 @@ public class App
}
catch ( IOException e )
{
System.out.println( "error while trying to read the properties for the service." );
e.printStackTrace();
logger.error( "error '{}' while trying to read the properties for the service, stopping app.",
e.getMessage(), e );
System.exit( 0 );
}
......@@ -79,8 +83,7 @@ public class App
}
catch ( InterruptedException e )
{
System.out.println( "Error while taking the watchkey from the watcher..." );
e.printStackTrace();
logger.error( "Error while taking the watchkey from the watcher, exiting application...", e );
System.exit( 0 );
}
......@@ -99,7 +102,7 @@ public class App
{
// System.out.println("Delete: " + event.context().toString());
if ( isFileNameAllowed( event.context().toString() ))
sendWebHookEvent( event, "-> removed a file: " );
sendWebHookEvent( event, "-> removed/moved a file: " );
}
if ( event.kind() == StandardWatchEventKinds.ENTRY_MODIFY )
{
......@@ -112,8 +115,9 @@ public class App
}
}
} catch (Exception e) {
System.out.println( "ooops, something went wrong, exiting app: " + e.toString() );
} catch ( Exception e ) {
logger.error( "ooops, something went wrong, exiting app: " + e.getMessage(), e );
// System.out.println( "ooops, something went wrong, exiting app: " + e.toString() );
System.exit( 0 );
}
}
......@@ -211,7 +215,7 @@ public class App
String text = intro + event.context().toString();
if ( webhook_url.isEmpty() ) {
System.out.println( "Invalid Slack webhook URL provided..." );
logger.error( "Invalid Slack webhook URL provided, stopping application..." );
System.exit( 0 );
}
......@@ -238,21 +242,19 @@ public class App
}
catch ( UnsupportedEncodingException e )
{
System.out.println( "error while trying to construct the JSON String entity..." );
e.printStackTrace();
logger.error( "error while trying to construct the JSON String entity: " + e.getMessage(), e );
System.exit( 0 );
}
try
{
System.out.println( "trying to send http post: " + httpPost.toString() );
logger.info( "trying to send http post: {}...", httpPost.toString() );
HttpResponse response = httpclient.execute( httpPost );
System.out.println( "http post response: " + response.getStatusLine().getStatusCode() );
logger.info( "http post response: {}...", response.getStatusLine().getStatusCode() );
}
catch ( IOException e )
{
System.out.println( "something went wrong while trying to send a HTTP post: " + e.getMessage() + "... \n" );
e.printStackTrace();
logger.error( "something went wrong while trying to send a HTTP post: " + e.getMessage(), e );
System.exit( 0 );
}
}
......@@ -295,7 +297,7 @@ public class App
String proxy = getProperties_ProxyURL();
if (!getProperties_ProxyPort().isEmpty());
proxy = proxy + getProperties_ProxyPort();
System.out.println( "connect over proxy: " + proxy );
logger.info( "connect over proxy: {}...", proxy );
return proxy;
}
return "";
......
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="console"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment