-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #201
- Loading branch information
Showing
7 changed files
with
80 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
leakcanary-android/src/main/java/com/squareup/leakcanary/CanaryLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.squareup.leakcanary; | ||
|
||
import android.util.Log; | ||
|
||
public final class CanaryLog { | ||
|
||
private static volatile Logger logger = new DefaultLogger(); | ||
|
||
public interface Logger { | ||
void d(String message, Object... args); | ||
|
||
void d(Throwable throwable, String message, Object... args); | ||
} | ||
|
||
private static class DefaultLogger implements Logger { | ||
|
||
@Override public void d(String message, Object... args) { | ||
String formatted = String.format(message, args); | ||
if (formatted.length() < 4000) { | ||
Log.d("LeakCanary", formatted); | ||
} else { | ||
String[] lines = formatted.split("\n"); | ||
for (String line : lines) { | ||
Log.d("LeakCanary", line); | ||
} | ||
} | ||
} | ||
|
||
@Override public void d(Throwable throwable, String message, Object... args) { | ||
d(String.format(message, args) + '\n' + Log.getStackTraceString(throwable)); | ||
} | ||
} | ||
|
||
public static void setLogger(Logger logger) { | ||
CanaryLog.logger = logger; | ||
} | ||
|
||
public static void d(String message, Object... args) { | ||
// Local variable to prevent the ref from becoming null after the null check. | ||
Logger logger = CanaryLog.logger; | ||
if (logger == null) { | ||
return; | ||
} | ||
logger.d(message, args); | ||
} | ||
|
||
public static void d(Throwable throwable, String message, Object... args) { | ||
// Local variable to prevent the ref from becoming null after the null check. | ||
Logger logger = CanaryLog.logger; | ||
if (logger == null) { | ||
return; | ||
} | ||
logger.d(throwable, message, args); | ||
} | ||
|
||
private CanaryLog() { | ||
throw new AssertionError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters