Permalink
Browse files

TFJ-718 make logger configurable via twitter4j.properties

  • Loading branch information...
1 parent ddb167f commit 02b3dab5d1762fc4579815c54bc29bb80332870b @yusuke committed Nov 23, 2012
@@ -121,4 +121,6 @@
long getContributingTo();
String getDispatcherImpl();
+
+ String getLoggerFactory();
}
@@ -60,12 +60,12 @@
private String oAuthAuthenticationURL;
private String restBaseURL;
- private String searchBaseURL;
private String streamBaseURL;
private String userStreamBaseURL;
private String siteStreamBaseURL;
private String dispatcherImpl;
+ private String loggerFactory;
private int asyncNumThreads;
@@ -176,6 +176,7 @@ protected ConfigurationBase() {
setSiteStreamBaseURL(DEFAULT_SITE_STREAM_BASE_URL);
setDispatcherImpl("twitter4j.internal.async.DispatcherImpl");
+ setLoggerFactory(null);
setUserStreamRepliesAllEnabled(false);
setStallWarningsEnabled(true);
@@ -602,6 +603,15 @@ protected final void setDispatcherImpl(String dispatcherImpl) {
this.dispatcherImpl = dispatcherImpl;
}
+ @Override
+ public String getLoggerFactory() {
+ return loggerFactory;
+ }
+
+ protected final void setLoggerFactory(String loggerImpl) {
+ this.loggerFactory = loggerImpl;
+ }
+
protected final void setIncludeRTsEnbled(boolean enabled) {
this.includeRTsEnabled = enabled;
}
@@ -706,6 +716,7 @@ public boolean equals(Object o) {
if (IS_DALVIK != that.IS_DALVIK) return false;
if (IS_GAE != that.IS_GAE) return false;
if (asyncNumThreads != that.asyncNumThreads) return false;
+ if (contributingTo != that.contributingTo) return false;
if (debug != that.debug) return false;
if (defaultMaxPerRoute != that.defaultMaxPerRoute) return false;
if (gzipEnabled != that.gzipEnabled) return false;
@@ -716,6 +727,7 @@ public boolean equals(Object o) {
if (httpRetryIntervalSeconds != that.httpRetryIntervalSeconds) return false;
if (httpStreamingReadTimeout != that.httpStreamingReadTimeout) return false;
if (includeEntitiesEnabled != that.includeEntitiesEnabled) return false;
+ if (includeMyRetweetEnabled != that.includeMyRetweetEnabled) return false;
if (includeRTsEnabled != that.includeRTsEnabled) return false;
if (jsonStoreEnabled != that.jsonStoreEnabled) return false;
if (maxTotalConnections != that.maxTotalConnections) return false;
@@ -735,6 +747,8 @@ public boolean equals(Object o) {
return false;
if (httpProxyUser != null ? !httpProxyUser.equals(that.httpProxyUser) : that.httpProxyUser != null)
return false;
+ if (loggerFactory != null ? !loggerFactory.equals(that.loggerFactory) : that.loggerFactory != null)
+ return false;
if (mediaProvider != null ? !mediaProvider.equals(that.mediaProvider) : that.mediaProvider != null)
return false;
if (mediaProviderAPIKey != null ? !mediaProviderAPIKey.equals(that.mediaProviderAPIKey) : that.mediaProviderAPIKey != null)
@@ -761,8 +775,6 @@ public boolean equals(Object o) {
if (requestHeaders != null ? !requestHeaders.equals(that.requestHeaders) : that.requestHeaders != null)
return false;
if (restBaseURL != null ? !restBaseURL.equals(that.restBaseURL) : that.restBaseURL != null) return false;
- if (searchBaseURL != null ? !searchBaseURL.equals(that.searchBaseURL) : that.searchBaseURL != null)
- return false;
if (siteStreamBaseURL != null ? !siteStreamBaseURL.equals(that.siteStreamBaseURL) : that.siteStreamBaseURL != null)
return false;
if (streamBaseURL != null ? !streamBaseURL.equals(that.streamBaseURL) : that.streamBaseURL != null)
@@ -804,14 +816,16 @@ public int hashCode() {
result = 31 * result + (oAuthAccessTokenURL != null ? oAuthAccessTokenURL.hashCode() : 0);
result = 31 * result + (oAuthAuthenticationURL != null ? oAuthAuthenticationURL.hashCode() : 0);
result = 31 * result + (restBaseURL != null ? restBaseURL.hashCode() : 0);
- result = 31 * result + (searchBaseURL != null ? searchBaseURL.hashCode() : 0);
result = 31 * result + (streamBaseURL != null ? streamBaseURL.hashCode() : 0);
result = 31 * result + (userStreamBaseURL != null ? userStreamBaseURL.hashCode() : 0);
result = 31 * result + (siteStreamBaseURL != null ? siteStreamBaseURL.hashCode() : 0);
result = 31 * result + (dispatcherImpl != null ? dispatcherImpl.hashCode() : 0);
+ result = 31 * result + (loggerFactory != null ? loggerFactory.hashCode() : 0);
result = 31 * result + asyncNumThreads;
+ result = 31 * result + (int) (contributingTo ^ (contributingTo >>> 32));
result = 31 * result + (includeRTsEnabled ? 1 : 0);
result = 31 * result + (includeEntitiesEnabled ? 1 : 0);
+ result = 31 * result + (includeMyRetweetEnabled ? 1 : 0);
result = 31 * result + (jsonStoreEnabled ? 1 : 0);
result = 31 * result + (mbeanEnabled ? 1 : 0);
result = 31 * result + (userStreamRepliesAllEnabled ? 1 : 0);
@@ -857,14 +871,16 @@ public String toString() {
", oAuthAccessTokenURL='" + oAuthAccessTokenURL + '\'' +
", oAuthAuthenticationURL='" + oAuthAuthenticationURL + '\'' +
", restBaseURL='" + restBaseURL + '\'' +
- ", searchBaseURL='" + searchBaseURL + '\'' +
", streamBaseURL='" + streamBaseURL + '\'' +
", userStreamBaseURL='" + userStreamBaseURL + '\'' +
", siteStreamBaseURL='" + siteStreamBaseURL + '\'' +
", dispatcherImpl='" + dispatcherImpl + '\'' +
+ ", loggerFactory='" + loggerFactory + '\'' +
", asyncNumThreads=" + asyncNumThreads +
+ ", contributingTo=" + contributingTo +
", includeRTsEnabled=" + includeRTsEnabled +
", includeEntitiesEnabled=" + includeEntitiesEnabled +
+ ", includeMyRetweetEnabled=" + includeMyRetweetEnabled +
", jsonStoreEnabled=" + jsonStoreEnabled +
", mbeanEnabled=" + mbeanEnabled +
", userStreamRepliesAllEnabled=" + userStreamRepliesAllEnabled +
@@ -289,6 +289,12 @@ public ConfigurationBuilder setMediaProviderParameters(Properties props) {
return this;
}
+ public ConfigurationBuilder setLoggerImpl(String loggerImpl) {
+ checkNotBuilt();
+ configurationBean.setLoggerFactory(loggerImpl);
+ return this;
+ }
+
public Configuration build() {
checkNotBuilt();
configurationBean.cacheInstance();
@@ -75,6 +75,7 @@
public static final String INCLUDE_RTS = "includeRTs";
public static final String INCLUDE_ENTITIES = "includeEntities";
public static final String INCLUDE_MY_RETWEET = "includeMyRetweet";
+ public static final String LOGGER_FACTORY = "loggerFactory";
public static final String JSON_STORE_ENABLED = "jsonStoreEnabled";
public static final String MBEAN_ENABLED = "mbeanEnabled";
public static final String STREAM_USER_REPLIES_ALL = "stream.user.repliesAll";
@@ -345,6 +346,9 @@ private void setFieldsWithPrefix(Properties props, String prefix) {
if (notNull(props, prefix, INCLUDE_MY_RETWEET)) {
setIncludeMyRetweetEnabled(getBoolean(props, prefix, INCLUDE_MY_RETWEET));
}
+ if (notNull(props, prefix, LOGGER_FACTORY)) {
+ setLoggerFactory(getString(props, prefix, LOGGER_FACTORY));
+ }
if (notNull(props, prefix, JSON_STORE_ENABLED)) {
setJSONStoreEnabled(getBoolean(props, prefix, JSON_STORE_ENABLED));
}
@@ -32,11 +32,19 @@
static {
LoggerFactory loggerFactory = null;
- //-Dtwitter4j.debug=true -Dtwitter4j.loggerFactory=twitter4j.internal.logging.StdOutLoggerFactory
+ // -Dtwitter4j.debug=true -Dtwitter4j.loggerFactory=twitter4j.internal.logging.StdOutLoggerFactory
String loggerFactoryImpl = System.getProperty(LOGGER_FACTORY_IMPLEMENTATION);
if (loggerFactoryImpl != null) {
loggerFactory = getLoggerFactoryIfAvailable(loggerFactoryImpl, loggerFactoryImpl);
}
+
+ Configuration conf = ConfigurationContext.getInstance();
+ // configuration in twitter4j.properties
+ // loggerFactory=twitter4j.internal.logging.StdOutLoggerFactory
+ loggerFactoryImpl = conf.getLoggerFactory();
+ if (loggerFactoryImpl != null) {
+ loggerFactory = getLoggerFactoryIfAvailable(loggerFactoryImpl, loggerFactoryImpl);
+ }
// use SLF4J if it's found in the classpath
if (null == loggerFactory) {
loggerFactory = getLoggerFactoryIfAvailable("org.slf4j.impl.StaticLoggerBinder", "twitter4j.internal.logging.SLF4JLoggerFactory");
@@ -59,7 +67,6 @@
}
LOGGER_FACTORY = loggerFactory;
- Configuration conf = ConfigurationContext.getInstance();
try {
Method method = conf.getClass().getMethod("dumpConfiguration", new Class[]{});
method.setAccessible(true);

0 comments on commit 02b3dab

Please sign in to comment.