Skip to content

Commit f9b81d2

Browse files
authored
SLF4J Integration (firebase#53)
* Using JUnit assumptions to skip tests instead of explicit returns * Replaced internal.Log with SLF4J * Integrating SLF4J into DB code * Removed unused Log class * Cleaned up log message generation * Updated javadoc comments
1 parent 9cc1d3c commit f9b81d2

22 files changed

Lines changed: 106 additions & 125 deletions

‎pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@
329329
<artifactId>guava</artifactId>
330330
<version>20.0</version>
331331
</dependency>
332+
<dependency>
333+
<groupId>org.slf4j</groupId>
334+
<artifactId>slf4j-api</artifactId>
335+
<version>1.7.25</version>
336+
</dependency>
332337
<dependency>
333338
<groupId>org.mockito</groupId>
334339
<artifactId>mockito-core</artifactId>

‎src/main/java/com/google/firebase/FirebaseApp.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.firebase.internal.FirebaseExecutors;
3434
import com.google.firebase.internal.FirebaseService;
3535
import com.google.firebase.internal.GetTokenResult;
36-
import com.google.firebase.internal.Log;
3736
import com.google.firebase.internal.NonNull;
3837
import com.google.firebase.internal.Nullable;
3938
import com.google.firebase.tasks.Continuation;
@@ -51,6 +50,8 @@
5150
import java.util.concurrent.TimeUnit;
5251
import java.util.concurrent.atomic.AtomicBoolean;
5352
import java.util.concurrent.atomic.AtomicReference;
53+
import org.slf4j.Logger;
54+
import org.slf4j.LoggerFactory;
5455

5556
/**
5657
* The entry point of Firebase SDKs. It holds common configuration and state for Firebase APIs. Most
@@ -64,6 +65,8 @@
6465
*/
6566
public class FirebaseApp {
6667

68+
private static final Logger logger = LoggerFactory.getLogger(FirebaseApp.class);
69+
6770
/** A map of (name, FirebaseApp) instances. */
6871
private static final Map<String, FirebaseApp> instances = new HashMap<>();
6972

@@ -360,9 +363,8 @@ public GetTokenResult then(@NonNull Task<GoogleOAuthAccessToken> task)
360363
if (refreshDelay > 0) {
361364
tokenRefresher.scheduleRefresh(refreshDelay);
362365
} else {
363-
Log.w("FirebaseApp", "Token expiry ("
364-
+ googleOAuthToken.getExpiryTime() + ") is less than 5 minutes in the "
365-
+ "future. Not scheduling a proactive refresh.");
366+
logger.warn("Token expiry ({}) is less than 5 minutes in the future. Not "
367+
+ "scheduling a proactive refresh.", googleOAuthToken.getAccessToken());
366368
}
367369
}
368370
}

‎src/main/java/com/google/firebase/database/FirebaseDatabase.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ public void goOffline() {
263263
* diagnostic logging, and {@link Logger.Level#NONE NONE} to disable all logging.
264264
*
265265
* @param logLevel The desired minimum log level
266+
* @deprecated This method will be removed in a future release. Use SLF4J-based logging instead.
267+
* For example, add the slf4j-simple.jar to the classpath to log to STDERR. See
268+
* <a href="https://www.slf4j.org/manual.html">SLF4J user manual</a> for more details.
266269
*/
267270
public synchronized void setLogLevel(Logger.Level logLevel) {
268271
synchronized (lock) {

‎src/main/java/com/google/firebase/database/Logger.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616

1717
package com.google.firebase.database;
1818

19-
/** This interface is used to setup logging for Firebase Database. */
19+
/**
20+
* This interface is used to setup logging for Firebase Database.
21+
*
22+
* @deprecated Use SLF4J-based logging
23+
*/
2024
public interface Logger {
2125

22-
/** The log levels used by the Firebase Database library */
26+
/**
27+
* The log levels used by the Firebase Database library
28+
*
29+
* @deprecated Use SLF4J-based logging
30+
*/
2331
enum Level {
2432
DEBUG,
2533
INFO,

‎src/main/java/com/google/firebase/database/connection/Connection.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Connection(
5454
long connId = connectionIds++;
5555
this.hostInfo = hostInfo;
5656
this.delegate = delegate;
57-
this.logger = new LogWrapper(context.getLogger(), "Connection", "conn_" + connId);
57+
this.logger = new LogWrapper(context.getLogger(), Connection.class, "conn_" + connId);
5858
this.state = State.REALTIME_CONNECTING;
5959
this.conn = new WebsocketConnection(context, hostInfo, cachedHost, this, optLastSessionId);
6060
}

‎src/main/java/com/google/firebase/database/connection/PersistentConnectionImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ public PersistentConnectionImpl(
135135
this.outstandingPuts = new HashMap<>();
136136
this.onDisconnectRequestQueue = new ArrayList<>();
137137
this.retryHelper =
138-
new RetryHelper.Builder(this.executorService, context.getLogger(), "ConnectionRetryHelper")
138+
new RetryHelper.Builder(this.executorService, context.getLogger(), RetryHelper.class)
139139
.withMinDelayAfterFailure(1000)
140140
.withRetryExponent(1.3)
141141
.withMaxDelay(30 * 1000)
142142
.withJitterFactor(0.7)
143143
.build();
144144

145145
long connId = connectionIds++;
146-
this.logger = new LogWrapper(context.getLogger(), "PersistentConnection", "pc_" + connId);
146+
this.logger = new LogWrapper(context.getLogger(), PersistentConnection.class, "pc_" + connId);
147147
this.lastSessionId = null;
148148
doIdleCheck();
149149
}

‎src/main/java/com/google/firebase/database/connection/WebsocketConnection.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public WebsocketConnection(
6262
this.executorService = connectionContext.getExecutorService();
6363
this.delegate = delegate;
6464
long connId = connectionId++;
65-
logger = new LogWrapper(connectionContext.getLogger(), "WebSocket", "ws_" + connId);
65+
logger = new LogWrapper(connectionContext.getLogger(), WebsocketConnection.class,
66+
"ws_" + connId);
6667
conn = createConnection(hostInfo, optCachedHost, optLastSessionId);
6768
}
6869

‎src/main/java/com/google/firebase/database/connection/util/RetryHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static class Builder {
125125
private long retryMaxDelay = 30 * 1000;
126126
private double retryExponent = 1.3;
127127

128-
public Builder(ScheduledExecutorService service, Logger logger, String tag) {
128+
public Builder(ScheduledExecutorService service, Logger logger, Class tag) {
129129
this.service = service;
130130
this.logger = new LogWrapper(logger, tag);
131131
}

‎src/main/java/com/google/firebase/database/core/Context.java‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,21 @@ protected void assertUnfrozen() {
141141
}
142142
}
143143

144-
public List<String> getOptDebugLogComponents() {
145-
return this.loggedComponents;
146-
}
147-
148-
public Logger.Level getLogLevel() {
149-
return this.logLevel;
150-
}
151-
152-
public Logger getLogger() {
153-
return this.logger;
144+
public LogWrapper getLogger(String component) {
145+
return new LogWrapper(logger, component, null);
154146
}
155147

156-
public LogWrapper getLogger(String component) {
148+
public LogWrapper getLogger(Class component) {
157149
return new LogWrapper(logger, component);
158150
}
159151

160-
public LogWrapper getLogger(String component, String prefix) {
152+
public LogWrapper getLogger(Class component, String prefix) {
161153
return new LogWrapper(logger, component, prefix);
162154
}
163155

164156
public ConnectionContext getConnectionContext() {
165157
return new ConnectionContext(
166-
this.getLogger(),
158+
this.logger,
167159
wrapAuthTokenProvider(this.getAuthTokenProvider()),
168160
this.getExecutorService(),
169161
this.isPersistenceEnabled(),

‎src/main/java/com/google/firebase/database/core/GaePlatform.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public EventTarget newEventTarget(Context ctx) {
8989

9090
@Override
9191
public RunLoop newRunLoop(final Context context) {
92-
final LogWrapper logger = context.getLogger("RunLoop");
92+
final LogWrapper logger = context.getLogger(RunLoop.class);
9393
return new DefaultRunLoop(getGaeThreadFactory(), /* periodicRestart= */ true, context) {
9494
@Override
9595
public void handleException(Throwable e) {

0 commit comments

Comments
 (0)