Migrated logging to SLF4J

This commit is contained in:
Patrick Gotthard 2014-04-14 19:13:40 +02:00
parent 0459e2f519
commit 950dd2f5d4
4 changed files with 40 additions and 12 deletions

View file

@ -71,6 +71,11 @@
<artifactId>jetty</artifactId> <artifactId>jetty</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View file

@ -29,10 +29,15 @@ import org.rometools.fetcher.FeedFetcher;
import org.rometools.fetcher.FetcherEvent; import org.rometools.fetcher.FetcherEvent;
import org.rometools.fetcher.FetcherException; import org.rometools.fetcher.FetcherException;
import org.rometools.fetcher.FetcherListener; import org.rometools.fetcher.FetcherListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
public abstract class AbstractFeedFetcher implements FeedFetcher { public abstract class AbstractFeedFetcher implements FeedFetcher {
private static final Logger LOG = LoggerFactory.getLogger(AbstractFeedFetcher.class);
private final Set<FetcherListener> fetcherEventListeners; private final Set<FetcherListener> fetcherEventListeners;
private String userAgent; private String userAgent;
private boolean usingDeltaEncoding; private boolean usingDeltaEncoding;
@ -54,11 +59,11 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
System.getProperties().putAll(props); System.getProperties().putAll(props);
inputStream.close(); inputStream.close();
} else { } else {
System.err.println("Could not find " + resourceName + " on classpath"); LOG.warn("Could not find {} on classpath", resourceName);
} }
} catch (final IOException e) { } catch (final IOException e) {
// do nothing - we don't want to fail just because we could not find the version // do nothing - we don't want to fail just because we could not find the version
System.err.println("Error reading " + resourceName + " from classpath: " + e.getMessage()); LOG.error("Error reading {} from classpath: {}", resourceName, e.getMessage());
} }
setUserAgent(DEFAULT_USER_AGENT + " Ver: " + System.getProperty("rome.fetcher.version", "UNKNOWN")); setUserAgent(DEFAULT_USER_AGENT + " Ver: " + System.getProperty("rome.fetcher.version", "UNKNOWN"));

View file

@ -35,6 +35,8 @@ import org.rometools.fetcher.FetcherException;
import org.rometools.fetcher.FetcherListener; import org.rometools.fetcher.FetcherListener;
import org.rometools.fetcher.impl.FeedFetcherCache; import org.rometools.fetcher.impl.FeedFetcherCache;
import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HashMapFeedInfoCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntry;
@ -45,6 +47,8 @@ import com.sun.syndication.feed.synd.SyndFeed;
*/ */
public abstract class AbstractJettyTest extends TestCase { public abstract class AbstractJettyTest extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(AbstractJettyTest.class);
private HttpServer server; private HttpServer server;
private final int testPort = 8283; private final int testPort = 8283;
@ -84,6 +88,7 @@ public abstract class AbstractJettyTest extends TestCase {
* @throws InterruptedException * @throws InterruptedException
*/ */
private void setupServer() throws InterruptedException { private void setupServer() throws InterruptedException {
// Create the server // Create the server
if (server != null) { if (server != null) {
server.stop(); server.stop();
@ -146,13 +151,13 @@ public abstract class AbstractJettyTest extends TestCase {
public void fetcherEvent(final FetcherEvent event) { public void fetcherEvent(final FetcherEvent event) {
final String eventType = event.getEventType(); final String eventType = event.getEventType();
if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) { if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
System.err.println("\tEVENT: Feed Polled. URL = " + event.getUrlString()); LOG.debug("\tEVENT: Feed Polled. URL = " + event.getUrlString());
polled = true; polled = true;
} else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) { } else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
System.err.println("\tEVENT: Feed Retrieved. URL = " + event.getUrlString()); LOG.debug("\tEVENT: Feed Retrieved. URL = " + event.getUrlString());
retrieved = true; retrieved = true;
} else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) { } else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
System.err.println("\tEVENT: Feed Unchanged. URL = " + event.getUrlString()); LOG.debug("\tEVENT: Feed Unchanged. URL = " + event.getUrlString());
unchanged = true; unchanged = true;
} }
} }
@ -260,8 +265,8 @@ public abstract class AbstractJettyTest extends TestCase {
public void testUserAgent() { public void testUserAgent() {
final FeedFetcher feedFetcher = getFeedFetcher(); final FeedFetcher feedFetcher = getFeedFetcher();
// System.out.println(feedFetcher.getUserAgent()); // LOG.debug(feedFetcher.getUserAgent());
// System.out.println(System.getProperty("rome.fetcher.version", "UNKNOWN")); // LOG.debug(System.getProperty("rome.fetcher.version", "UNKNOWN"));
assertEquals("Rome Client (http://tinyurl.com/64t5n) Ver: " + System.getProperty("rome.fetcher.version", "UNKNOWN"), feedFetcher.getUserAgent()); assertEquals("Rome Client (http://tinyurl.com/64t5n) Ver: " + System.getProperty("rome.fetcher.version", "UNKNOWN"), feedFetcher.getUserAgent());
} }

View file

@ -0,0 +1,13 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="STDOUT" />
</root>
</configuration>