Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- [changed] Dropped support for App Engine's Java 7 runtime. Developers
are advised to use the Admin SDK with Java 8 when deploying to App
Engine.
- [changed] Removed the deprecated `FirebaseDatabase.setLogLevel()` API
and the related logging utilities. Developers should use SLF4J to
configure logging directly.

# v5.9.0

Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/google/firebase/database/FirebaseDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,6 @@ public void goOffline() {
RepoManager.interrupt(ensureRepo());
}

/**
* By default, this is set to {@link Logger.Level#INFO INFO}. This includes any internal errors
* ({@link Logger.Level#ERROR ERROR}) and any security debug messages ({@link Logger.Level#INFO
* INFO}) that the client receives. Set to {@link Logger.Level#DEBUG DEBUG} to turn on the
* diagnostic logging, and {@link Logger.Level#NONE NONE} to disable all logging.
*
* @param logLevel The desired minimum log level
* @deprecated This method will be removed in a future release. Use SLF4J-based logging instead.
* For example, add the slf4j-simple.jar to the classpath to log to STDERR. See
* <a href="https://www.slf4j.org/manual.html">SLF4J user manual</a> for more details.
*/
public synchronized void setLogLevel(Logger.Level logLevel) {
synchronized (lock) {
assertUnfrozen("setLogLevel");
this.config.setLogLevel(logLevel);
}
}

/**
* The Firebase Database client will cache synchronized data and keep track of all writes you've
* initiated while your application is running. It seamlessly handles intermittent network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package com.google.firebase.database.connection;

import com.google.common.annotations.VisibleForTesting;
import com.google.firebase.database.logging.LogWrapper;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Connection implements WebsocketConnection.Delegate {

Expand All @@ -39,11 +40,14 @@ class Connection implements WebsocketConnection.Delegate {
private static final String SERVER_HELLO_TIMESTAMP = "ts";
private static final String SERVER_HELLO_HOST = "h";
private static final String SERVER_HELLO_SESSION_ID = "s";

private static final Logger logger = LoggerFactory.getLogger(Connection.class);

private static long connectionIds = 0;

private final LogWrapper logger;
private final HostInfo hostInfo;
private final Delegate delegate;
private final String label;

private WebsocketConnection conn;
private State state;
Expand All @@ -54,36 +58,31 @@ class Connection implements WebsocketConnection.Delegate {
String cachedHost,
Delegate delegate,
String optLastSessionId) {
this(context, hostInfo, delegate,
this(hostInfo, delegate,
new DefaultWebsocketConnectionFactory(context, hostInfo, cachedHost, optLastSessionId));
}

@VisibleForTesting
Connection(
ConnectionContext context,
HostInfo hostInfo,
Delegate delegate,
WebsocketConnectionFactory connFactory) {
long connId = connectionIds++;
this.hostInfo = hostInfo;
this.delegate = delegate;
this.logger = new LogWrapper(context.getLogger(), Connection.class, "conn_" + connId);
this.label = "[conn_" + connId + "]";
this.state = State.REALTIME_CONNECTING;
this.conn = connFactory.newConnection(this);
}

public void open() {
if (logger.logsDebug()) {
logger.debug("Opening a connection");
}
logger.debug("{} Opening a connection", label);
conn.open();
}

public void close(DisconnectReason reason) {
if (state != State.REALTIME_DISCONNECTED) {
if (logger.logsDebug()) {
logger.debug("closing realtime connection");
}
logger.debug("{} Closing realtime connection", label);
state = State.REALTIME_DISCONNECTED;

if (conn != null) {
Expand Down Expand Up @@ -123,21 +122,14 @@ public void onMessage(Map<String, Object> message) {
Map<String, Object> data = (Map<String, Object>) message.get(SERVER_ENVELOPE_DATA);
onControlMessage(data);
} else {
if (logger.logsDebug()) {
logger.debug("Ignoring unknown server message type: " + messageType);
}
logger.debug("{} Ignoring unknown server message type: {}", label, messageType);
}
} else {
if (logger.logsDebug()) {
logger.debug(
"Failed to parse server message: missing message type:" + message.toString());
}
logger.debug("{} Failed to parse server message: missing message type: {}", label, message);
close();
}
} catch (ClassCastException e) {
if (logger.logsDebug()) {
logger.debug("Failed to parse server message: " + e.toString());
}
logger.debug("{} Failed to parse server message", label, e);
close();
}
}
Expand All @@ -146,30 +138,22 @@ public void onMessage(Map<String, Object> message) {
public void onDisconnect(boolean wasEverConnected) {
conn = null;
if (!wasEverConnected && state == State.REALTIME_CONNECTING) {
if (logger.logsDebug()) {
logger.debug("Realtime connection failed");
}
logger.debug("{} Realtime connection failed", label);
} else {
if (logger.logsDebug()) {
logger.debug("Realtime connection lost");
}
logger.debug("{} Realtime connection lost", label);
}

close();
}

private void onDataMessage(Map<String, Object> data) {
if (logger.logsDebug()) {
logger.debug("received data message: " + data.toString());
}
logger.debug("{} Received data message: {}", label, data);
// We don't do anything with data messages, just kick them up a level
delegate.onDataMessage(data);
}

private void onControlMessage(Map<String, Object> data) {
if (logger.logsDebug()) {
logger.debug("Got control message: " + data.toString());
}
logger.debug("{} Got control message: {}", label, data);
try {
String messageType = (String) data.get(SERVER_CONTROL_MESSAGE_TYPE);
if (messageType != null) {
Expand All @@ -185,28 +169,20 @@ private void onControlMessage(Map<String, Object> data) {
(Map<String, Object>) data.get(SERVER_CONTROL_MESSAGE_DATA);
onHandshake(handshakeData);
} else {
if (logger.logsDebug()) {
logger.debug("Ignoring unknown control message: " + messageType);
}
logger.debug("{} Ignoring unknown control message: {}", label, messageType);
}
} else {
if (logger.logsDebug()) {
logger.debug("Got invalid control message: " + data.toString());
}
logger.debug("{} Got invalid control message: {}", label, data);
close();
}
} catch (ClassCastException e) {
if (logger.logsDebug()) {
logger.debug("Failed to parse control message: " + e.toString());
}
logger.debug("{} Failed to parse control message", label, e);
close();
}
}

private void onConnectionShutdown(String reason) {
if (logger.logsDebug()) {
logger.debug("Connection shutdown command received. Shutting down...");
}
logger.debug("{} Connection shutdown command received. Shutting down...", label);
delegate.onKill(reason);
close();
}
Expand All @@ -224,21 +200,15 @@ private void onHandshake(Map<String, Object> handshake) {
}

private void onConnectionReady(long timestamp, String sessionId) {
if (logger.logsDebug()) {
logger.debug("realtime connection established");
}
logger.debug("{} Realtime connection established", label);
state = State.REALTIME_CONNECTED;
delegate.onReady(timestamp, sessionId);
}

private void onReset(String host) {
if (logger.logsDebug()) {
logger.debug(
"Got a reset; killing connection to "
+ this.hostInfo.getHost()
+ "; Updating internalHost to "
+ host);
}
logger.debug(
"{} Got a reset; killing connection to {}; Updating internalHost to {}",
label, hostInfo.getHost(), host);
delegate.onCacheHost(host);

// Explicitly close the connection with SERVER_RESET so calling code knows to reconnect
Expand All @@ -248,12 +218,12 @@ private void onReset(String host) {

private void sendData(Map<String, Object> data, boolean isSensitive) {
if (state != State.REALTIME_CONNECTED) {
logger.debug("Tried to send on an unconnected connection");
logger.debug("{} Tried to send on an unconnected connection", label);
} else {
if (isSensitive) {
logger.debug("Sending data (contents hidden)");
logger.debug("{} Sending data (contents hidden)", label);
} else {
logger.debug("Sending data: %s", data);
logger.debug("{} Sending data: {}", label, data);
}
conn.send(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@

package com.google.firebase.database.connection;

import com.google.firebase.database.logging.Logger;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;

public class ConnectionContext {

private final ScheduledExecutorService executorService;
private final ConnectionAuthTokenProvider authTokenProvider;
private final Logger logger;
private final boolean persistenceEnabled;
private final String clientSdkVersion;
private final String userAgent;
private final ThreadFactory threadFactory;

public ConnectionContext(
Logger logger,
ConnectionAuthTokenProvider authTokenProvider,
ScheduledExecutorService executorService,
boolean persistenceEnabled,
String clientSdkVersion,
String userAgent,
ThreadFactory threadFactory) {
this.logger = logger;
this.authTokenProvider = authTokenProvider;
this.executorService = executorService;
this.persistenceEnabled = persistenceEnabled;
Expand All @@ -48,10 +43,6 @@ public ConnectionContext(
this.threadFactory = threadFactory;
}

public Logger getLogger() {
return this.logger;
}

public ConnectionAuthTokenProvider getAuthTokenProvider() {
return this.authTokenProvider;
}
Expand Down
Loading