From c761538c677eadad381347b10ea28d76e65fe22f Mon Sep 17 00:00:00 2001 From: Shashikant <60922344+shashikantkonded-git@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:39:09 +0530 Subject: [PATCH 1/2] Route the logs to custom logger --- .../android/exoplayer2/util/CustomLogger.java | 36 +++++++++++++++++++ .../google/android/exoplayer2/util/Log.java | 23 ++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 library/common/src/main/java/com/google/android/exoplayer2/util/CustomLogger.java diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/CustomLogger.java b/library/common/src/main/java/com/google/android/exoplayer2/util/CustomLogger.java new file mode 100644 index 0000000000..55756aa88d --- /dev/null +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/CustomLogger.java @@ -0,0 +1,36 @@ +package com.google.android.exoplayer2.util; + +/** + * Interface to be implemented by a custom logger if logging required is other than simple {@link android.util.Log} + *
+ * {@link Log.setCustomLogger(CustomLogger)} should be used to provide the implementation
+ */
+public interface CustomLogger {
+ /**
+ * Analogous to {@link android.util.Log#d(String, String)}
+ *
+ * @see android.util.Log#d(String, String)
+ */
+ void d(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#i(String, String)}
+ *
+ * @see android.util.Log#i(String, String)
+ */
+ void i(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#w(String, String)}
+ *
+ * @see android.util.Log#w(String, String)
+ */
+ void w(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#e(String, String)}
+ *
+ * @see android.util.Log#e(String, String)
+ */
+ void e(String tag, String message);
+}
diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
index afc67dca07..65b6b8778d 100644
--- a/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
+++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
@@ -71,6 +71,16 @@ public final class Log {
Log.logLevel = logLevel;
}
+ /**
+ * Sets a custom logger for the ExoPlayer logs.
+ * Logs are routed to this logger once this is initialized.
+ *
+ * @param customLogger - a {@link CustomLogger} implementation
+ */
+ public static void setCustomLogger(@Nullable CustomLogger customLogger) {
+ Log.customLogger = customLogger;
+ }
+
/**
* Sets whether stack traces of {@link Throwable}s will be logged to logcat. Stack trace logging
* is enabled by default.
@@ -87,6 +97,9 @@ public final class Log {
@Pure
public static void d(@Size(max = 23) String tag, String message) {
if (logLevel == LOG_LEVEL_ALL) {
+ if (customLogger != null) {
+ customLogger.d(tag, message);
+ }
android.util.Log.d(tag, message);
}
}
@@ -105,6 +118,9 @@ public final class Log {
@Pure
public static void i(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_INFO) {
+ if (customLogger != null) {
+ customLogger.i(tag, message);
+ }
android.util.Log.i(tag, message);
}
}
@@ -123,6 +139,9 @@ public final class Log {
@Pure
public static void w(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_WARNING) {
+ if (customLogger != null) {
+ customLogger.w(tag, message);
+ }
android.util.Log.w(tag, message);
}
}
@@ -141,6 +160,9 @@ public final class Log {
@Pure
public static void e(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_ERROR) {
+ if (customLogger != null) {
+ customLogger.e(tag, message);
+ }
android.util.Log.e(tag, message);
}
}
@@ -203,4 +225,5 @@ public final class Log {
}
return false;
}
+
}
From 010ca305fba8311cd2a03e123b848a8593c2bff7 Mon Sep 17 00:00:00 2001
From: Shashikant
+ * {@link Log.setCustomLogger(CustomLogger)} should be used to provide the implementation
+ */
+public interface CustomLogger {
+ /**
+ * Analogous to {@link android.util.Log#d(String, String)}
+ *
+ * @see android.util.Log#d(String, String)
+ */
+ void d(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#i(String, String)}
+ *
+ * @see android.util.Log#i(String, String)
+ */
+ void i(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#w(String, String)}
+ *
+ * @see android.util.Log#w(String, String)
+ */
+ void w(String tag, String message);
+
+ /**
+ * Analogous to {@link android.util.Log#e(String, String)}
+ *
+ * @see android.util.Log#e(String, String)
+ */
+ void e(String tag, String message);
+}
diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
index afc67dca07..65b6b8778d 100644
--- a/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
+++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Log.java
@@ -71,6 +71,16 @@ public final class Log {
Log.logLevel = logLevel;
}
+ /**
+ * Sets a custom logger for the ExoPlayer logs.
+ * Logs are routed to this logger once this is initialized.
+ *
+ * @param customLogger - a {@link CustomLogger} implementation
+ */
+ public static void setCustomLogger(@Nullable CustomLogger customLogger) {
+ Log.customLogger = customLogger;
+ }
+
/**
* Sets whether stack traces of {@link Throwable}s will be logged to logcat. Stack trace logging
* is enabled by default.
@@ -87,6 +97,9 @@ public final class Log {
@Pure
public static void d(@Size(max = 23) String tag, String message) {
if (logLevel == LOG_LEVEL_ALL) {
+ if (customLogger != null) {
+ customLogger.d(tag, message);
+ }
android.util.Log.d(tag, message);
}
}
@@ -105,6 +118,9 @@ public final class Log {
@Pure
public static void i(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_INFO) {
+ if (customLogger != null) {
+ customLogger.i(tag, message);
+ }
android.util.Log.i(tag, message);
}
}
@@ -123,6 +139,9 @@ public final class Log {
@Pure
public static void w(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_WARNING) {
+ if (customLogger != null) {
+ customLogger.w(tag, message);
+ }
android.util.Log.w(tag, message);
}
}
@@ -141,6 +160,9 @@ public final class Log {
@Pure
public static void e(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_ERROR) {
+ if (customLogger != null) {
+ customLogger.e(tag, message);
+ }
android.util.Log.e(tag, message);
}
}
@@ -203,4 +225,5 @@ public final class Log {
}
return false;
}
+
}