Only catch UnsatisfiedLinkError in Logging.java.

BUG=

Review URL: https://codereview.webrtc.org/1375913005

Cr-Commit-Position: refs/heads/master@{#10169}
This commit is contained in:
jiayl
2015-10-05 05:27:45 -07:00
committed by Commit bot
parent f3a7c9d732
commit 4cd053fe88

View File

@ -19,14 +19,18 @@ import java.util.logging.Level;
/** Java wrapper for WebRTC logging. */
public class Logging {
private static final Logger fallbackLogger = Logger.getLogger("org.webrtc.Logging");
private static boolean tracingEnabled;
private static volatile boolean tracingEnabled;
private static volatile boolean nativeLibLoaded;
static {
try {
System.loadLibrary("jingle_peerconnection_so");
} catch (Throwable t) {
nativeLibLoaded = true;
} catch (UnsatisfiedLinkError t) {
// If native logging is unavailable, log to system log.
fallbackLogger.setLevel(Level.ALL);
fallbackLogger.log(Level.WARNING, "Failed to load jingle_peerconnection_so: ", t);
}
}
@ -60,10 +64,19 @@ public class Logging {
};
public static void enableLogThreads() {
if (!nativeLibLoaded) {
fallbackLogger.log(Level.WARNING, "Cannot enable log thread because native lib not loaded.");
return;
}
nativeEnableLogThreads();
}
public static void enableLogTimeStamps() {
if (!nativeLibLoaded) {
fallbackLogger.log(Level.WARNING,
"Cannot enable log timestamps because native lib not loaded.");
return;
}
nativeEnableLogTimeStamps();
}
@ -71,6 +84,11 @@ public class Logging {
// On Android, use "logcat:" for |path| to send output there.
public static synchronized void enableTracing(
String path, EnumSet<TraceLevel> levels, Severity severity) {
if (!nativeLibLoaded) {
fallbackLogger.log(Level.WARNING, "Cannot enable tracing because native lib not loaded.");
return;
}
if (tracingEnabled) {
return;
}
@ -84,12 +102,8 @@ public class Logging {
public static void log(Severity severity, String tag, String message) {
if (tracingEnabled) {
try {
nativeLog(severity.ordinal(), tag, message);
return;
} catch (Throwable t) {
// Don't log the error to avoid spamming.
}
nativeLog(severity.ordinal(), tag, message);
return;
}
// Fallback to system log.