Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route the logs to custom logger #10185

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Route the logs to custom logger
  • Loading branch information
shashikant-xgit authored and shashikantkonded-git committed Apr 14, 2022
commit 010ca305fba8311cd2a03e123b848a8593c2bff7
Original file line number Diff line number Diff line change
@@ -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}
* <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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public static void setLogLevel(@LogLevel int logLevel) {
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.
Expand All @@ -87,6 +97,9 @@ public static void setLogStackTraces(boolean logStackTraces) {
@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);
}
}
Expand All @@ -105,6 +118,9 @@ public static void d(@Size(max = 23) String tag, String message, @Nullable Throw
@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);
}
}
Expand All @@ -123,6 +139,9 @@ public static void i(@Size(max = 23) String tag, String message, @Nullable Throw
@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);
}
}
Expand All @@ -141,6 +160,9 @@ public static void w(@Size(max = 23) String tag, String message, @Nullable Throw
@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);
}
}
Expand Down Expand Up @@ -203,4 +225,5 @@ private static boolean isCausedByUnknownHostException(@Nullable Throwable throwa
}
return false;
}

}