Commit c761538c by Shashikant

Route the logs to custom logger

parent 8e57d371
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}
* <p>
* {@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);
}
...@@ -72,6 +72,16 @@ public final class Log { ...@@ -72,6 +72,16 @@ public final class Log {
} }
/** /**
* 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 * Sets whether stack traces of {@link Throwable}s will be logged to logcat. Stack trace logging
* is enabled by default. * is enabled by default.
* *
...@@ -87,6 +97,9 @@ public final class Log { ...@@ -87,6 +97,9 @@ public final class Log {
@Pure @Pure
public static void d(@Size(max = 23) String tag, String message) { public static void d(@Size(max = 23) String tag, String message) {
if (logLevel == LOG_LEVEL_ALL) { if (logLevel == LOG_LEVEL_ALL) {
if (customLogger != null) {
customLogger.d(tag, message);
}
android.util.Log.d(tag, message); android.util.Log.d(tag, message);
} }
} }
...@@ -105,6 +118,9 @@ public final class Log { ...@@ -105,6 +118,9 @@ public final class Log {
@Pure @Pure
public static void i(@Size(max = 23) String tag, String message) { public static void i(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_INFO) { if (logLevel <= LOG_LEVEL_INFO) {
if (customLogger != null) {
customLogger.i(tag, message);
}
android.util.Log.i(tag, message); android.util.Log.i(tag, message);
} }
} }
...@@ -123,6 +139,9 @@ public final class Log { ...@@ -123,6 +139,9 @@ public final class Log {
@Pure @Pure
public static void w(@Size(max = 23) String tag, String message) { public static void w(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_WARNING) { if (logLevel <= LOG_LEVEL_WARNING) {
if (customLogger != null) {
customLogger.w(tag, message);
}
android.util.Log.w(tag, message); android.util.Log.w(tag, message);
} }
} }
...@@ -141,6 +160,9 @@ public final class Log { ...@@ -141,6 +160,9 @@ public final class Log {
@Pure @Pure
public static void e(@Size(max = 23) String tag, String message) { public static void e(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_ERROR) { if (logLevel <= LOG_LEVEL_ERROR) {
if (customLogger != null) {
customLogger.e(tag, message);
}
android.util.Log.e(tag, message); android.util.Log.e(tag, message);
} }
} }
...@@ -203,4 +225,5 @@ public final class Log { ...@@ -203,4 +225,5 @@ public final class Log {
} }
return false; return false;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment