From 09bbb55fb1b316c49b420e157bf97470aa4ebd64 Mon Sep 17 00:00:00 2001 From: Ron Kuris Date: Mon, 1 Dec 2014 21:52:52 -0800 Subject: [PATCH] Use slf4j simple logger to get logs to stdout Logs were heading over to log4j before this; were they getting lost? --- build.gradle | 7 +++++++ src/main/groovy/offtopic/KafkaSubscriber.groovy | 4 +++- src/main/groovy/offtopic/OfftopicClient.groovy | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 62bb7b3..45d8c18 100644 --- a/build.gradle +++ b/build.gradle @@ -39,11 +39,18 @@ dependencies { compile 'org.apache.kafka:kafka_2.10:0.8.1.1+' + compile 'org.slf4j:log4j-over-slf4j:1.7.6' + compile 'org.slf4j:slf4j-simple:1.7.6' + testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' testCompile 'cglib:cglib-nodep:2.2.+' } //////////////////////////////////////////////////////////////////////////////// +configurations { + compile.exclude module: 'log4j' + compile.exclude module: 'slf4j-log4j12' +} test { testLogging { diff --git a/src/main/groovy/offtopic/KafkaSubscriber.groovy b/src/main/groovy/offtopic/KafkaSubscriber.groovy index 536bbe6..b0f3fb5 100644 --- a/src/main/groovy/offtopic/KafkaSubscriber.groovy +++ b/src/main/groovy/offtopic/KafkaSubscriber.groovy @@ -4,11 +4,13 @@ import kafka.consumer.ConsumerConfig; import kafka.consumer.KafkaStream; import kafka.javaapi.consumer.ConsumerConnector; import offtopic.curator.CuratorPool +import groovy.util.logging.Slf4j /** * KafkaSubscriber is a Kafka consumer consumer, largely cribbed from: * https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example */ +@Slf4j class KafkaSubscriber { String topic @@ -38,7 +40,7 @@ class KafkaSubscriber { public void consume() { if (this.consumer == null) { - println "no consumer, gtfo" + log.warn "no consumer, gtfo" return } diff --git a/src/main/groovy/offtopic/OfftopicClient.groovy b/src/main/groovy/offtopic/OfftopicClient.groovy index fcc4048..f2b6d55 100644 --- a/src/main/groovy/offtopic/OfftopicClient.groovy +++ b/src/main/groovy/offtopic/OfftopicClient.groovy @@ -1,9 +1,12 @@ package offtopic +import groovy.util.logging.Slf4j + /** * OfftopicClient coordinates the interactions between KafkaSubscriber objects * and the websocket interactions */ +@Slf4j class OfftopicClient { public int clientId = 0 @@ -44,9 +47,9 @@ class OfftopicClient { this.subscribers.each { subscriber -> Thread runner = new Thread({ subscriber.connect() - println "subscriber connected" + log.info "subscriber connected" subscriber.consume() - println "consume over!" + log.info "consume over!" }) runner.start() }