rootLogger.addAppender(warningsAppender);
// creates a custom logger and log messages
final Logger logger = Logger.getLogger(GatherStatusStream.class);
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
RawStreamListener rawListener = new RawStreamListener() {
@Override
public void onMessage(String rawString) {
cnt++;
logger.info(rawString);
if (cnt % 1000 == 0) {
System.out.println(cnt + " messages received.");
}
}
@Override
public void onException(Exception ex) {
logger.warn(ex);
}
};
twitterStream.addListener(rawListener);
twitterStream.sample();
}