Skip to content

Commit

Permalink
see 04/02 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Apr 2, 2018
1 parent 2a2887c commit 0cab34c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation project(':utilcode')
implementation project(':utilcode')
implementation project(':subutil')
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation 'com.r0adkll:slidableactivity:2.0.5'
// LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
implementation 'com.blankj:utilcode:1.13.6'
// implementation 'com.blankj:utilcode:1.13.6'
}


2 changes: 1 addition & 1 deletion app/src/main/java/com/blankj/androidutilcode/UtilsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void initLog() {
.setBorderSwitch(true)// 输出日志是否带边框开关,默认开
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
.setStackDeep(1);// log 栈深度,默认为 1
.setStackDeep(10);// log 栈深度,默认为 1
new Thread(new Runnable() {
@Override
public void run() {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Feb 27 13:02:08 CST 2017
#Sat Mar 31 15:05:28 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
46 changes: 25 additions & 21 deletions utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,17 @@ private static TagHead processTagAndHead(String tag) {
} else {
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
StackTraceElement targetElement = stackTrace[3];
String fileName = targetElement.getFileName();
String className;
// If name of file is null, should add
// "-keepattributes SourceFile,LineNumberTable" in proguard file.
if (fileName == null) {
className = targetElement.getClassName();
String[] classNameInfo = className.split("\\.");
if (classNameInfo.length > 0) {
className = classNameInfo[classNameInfo.length - 1];
}
int index = className.indexOf('$');
if (index != -1) {
className = className.substring(0, index);
}
fileName = className + ".java";
} else {
final String fileName = getFileName(targetElement);
if (sTagIsSpace && isSpace(tag)) {
int index = fileName.indexOf('.');// Use proguard may not find '.'.
className = index == -1 ? fileName : fileName.substring(0, index);
tag = index == -1 ? fileName : fileName.substring(0, index);
}
if (sTagIsSpace) tag = isSpace(tag) ? className : tag;
if (sLogHeadSwitch) {
String tName = Thread.currentThread().getName();
final String head = new Formatter()
.format("%s, %s(%s:%d)",
.format("%s, %s.%s(%s:%d)",
tName,
targetElement.getClassName(),
targetElement.getMethodName(),
fileName,
targetElement.getLineNumber())
Expand All @@ -265,10 +251,11 @@ private static TagHead processTagAndHead(String tag) {
for (int i = 1, len = consoleHead.length; i < len; ++i) {
targetElement = stackTrace[i + 3];
consoleHead[i] = new Formatter()
.format("%s%s(%s:%d)",
.format("%s%s.%s(%s:%d)",
space,
targetElement.getClassName(),
targetElement.getMethodName(),
targetElement.getFileName(),
getFileName(targetElement),
targetElement.getLineNumber())
.toString();
}
Expand All @@ -279,6 +266,23 @@ private static TagHead processTagAndHead(String tag) {
return new TagHead(tag, null, ": ");
}

private static String getFileName(final StackTraceElement targetElement) {
String fileName = targetElement.getFileName();
if (fileName != null) return fileName;
// If name of file is null, should add
// "-keepattributes SourceFile,LineNumberTable" in proguard file.
String className = targetElement.getClassName();
String[] classNameInfo = className.split("\\.");
if (classNameInfo.length > 0) {
className = classNameInfo[classNameInfo.length - 1];
}
int index = className.indexOf('$');
if (index != -1) {
className = className.substring(0, index);
}
return className + ".java";
}

private static String processBody(final int type, final Object... contents) {
String body = NULL;
if (contents != null) {
Expand Down

0 comments on commit 0cab34c

Please sign in to comment.