Permalink
Browse files

目前遗留bug:logger输出json时tag有误,timber输出时tail有误

  • Loading branch information...
tianzhijiexian committed Sep 29, 2017
1 parent 7b6a8c3 commit 9352ac60cf79dc70ac4d4fc91b6715a80b9e7b3b
Showing with 732 additions and 619 deletions.
  1. +13 −7 app/build.gradle
  2. +1 −0 app/src/main/AndroidManifest.xml
  3. +64 −110 app/src/main/java/com/orhanobut/loggersample/MainActivity.java
  4. +37 −0 app/src/main/java/com/orhanobut/loggersample/MyLogAdapter.java
  5. +28 −29 app/src/main/java/com/orhanobut/loggersample/XLogStyle.java
  6. +6 −6 app/src/main/java/com/orhanobut/loggersample/{ → model}/Dummy.java
  7. +2 −2 app/src/main/java/com/orhanobut/loggersample/{ → model}/Foo.java
  8. +1 −1 ...com/orhanobut/logger/util → app/src/main/java/com/orhanobut/loggersample/parser}/ArrayParser.java
  9. +7 −7 ...a/com/orhanobut/logger/util → app/src/main/java/com/orhanobut/loggersample/parser}/ObjParser.java
  10. +12 −12 ...m/orhanobut/logger/util → app/src/main/java/com/orhanobut/loggersample/parser}/XmlJsonParser.java
  11. +2 −2 app/src/main/java/com/orhanobut/loggersample/{ → timber}/CrashHandler.java
  12. +6 −1 app/src/main/java/com/orhanobut/loggersample/{ → timber}/CrashlyticsTree.java
  13. +13 −0 app/src/main/java/com/orhanobut/loggersample/timber/Foo01.java
  14. +145 −0 app/src/main/java/com/orhanobut/loggersample/timber/TimberActivity.java
  15. +38 −0 app/src/main/java/com/orhanobut/loggersample/timber/TimberDebugTree.java
  16. +3 −1 build.gradle
  17. +2 −2 gradle/wrapper/gradle-wrapper.properties
  18. +4 −2 lint/src/main/java/kale/log/lint/LogDetector.java
  19. +2 −2 lintaar/build.gradle
  20. +3 −5 logger/build.gradle
  21. +0 −75 logger/src/main/java/com/orhanobut/logger/LogBuilder.java
  22. +0 −68 logger/src/main/java/com/orhanobut/logger/LogPrintStyle.java
  23. +0 −90 logger/src/main/java/com/orhanobut/logger/LogPrinter.java
  24. +0 −162 logger/src/main/java/com/orhanobut/logger/Logger.java
  25. +0 −35 logger/src/main/java/com/orhanobut/logger/PrintStyle.java
  26. +38 −0 logger/src/main/java/com/orhanobut/logger/helper/AbsLogStyle.java
  27. +69 −0 logger/src/main/java/com/orhanobut/logger/helper/DefaultStyle.java
  28. +146 −0 logger/src/main/java/com/orhanobut/logger/helper/LogPrintHelper.java
  29. +90 −0 logger/src/main/java/com/orhanobut/logger/helper/LogSettings.java
View
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25'
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.orhanobut.loggersample"
minSdkVersion 14
targetSdkVersion 25
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
@@ -17,12 +17,18 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.orhanobut:logger:2.1.1'
compile 'com.jakewharton.timber:timber:4.5.1'
compile project(':logger')
compile project(':lintaar')
}
@@ -16,6 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".timber.TimberActivity" />
</application>
</manifest>
@@ -1,17 +1,15 @@
package com.orhanobut.loggersample;
import java.util.Arrays;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import com.orhanobut.logger.LogBuilder;
import com.orhanobut.logger.Logger;
import timber.log.Timber;
import com.orhanobut.logger.helper.LogSettings;
import com.orhanobut.loggersample.model.Dummy;
import com.orhanobut.loggersample.model.Foo;
import com.orhanobut.loggersample.timber.TimberActivity;
public class MainActivity extends AppCompatActivity {
@@ -22,35 +20,48 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Logger.uprootAll();
// lint check
System.out.println("lint error");
Log.d(TAG, "onCreate: lint error");
Logger.initialize(
LogBuilder.create()
.logPrintStyle(new XLogStyle())
.showMethodLink(true)
.showThreadInfo(true)
.tagPrefix("kale")
// .globalTag("globalTag")
.methodOffset(0)
.logPriority(BuildConfig.DEBUG ? Log.VERBOSE : Log.ASSERT)
.build()
);
if (!BuildConfig.DEBUG) {
// for release
Logger.plant(new CrashlyticsTree());
if (true) {
startActivity(new Intent(this, TimberActivity.class));
return;
}
LogSettings settings = new LogSettings.Builder()
.showMethodLink(true)
.showThreadInfo(true)
.tagPrefix("kale")
// .globalTag("GLOBAL-TAG")
.methodOffset(0)
.logPriority(BuildConfig.DEBUG ? Log.VERBOSE : Log.ASSERT)
.build();
Logger.addLogAdapter(new MyLogAdapter(settings));
// Logger.addLogAdapter(new AndroidLogAdapter());
Logger.d("debug");
Logger.e("error");
Logger.w("warning");
Logger.v("verbose");
Logger.i("information");
Logger.wtf("wtf!!!!");
levTest();
objTest();
jsonTest();
locationTest();
largeDataTest();
jsonTest();
String xml = "<name>\n"
+ " <first>Bill</first>\n"
+ " <last>Gates</last>\n"
+ "</name>";
Logger.xml(xml);
Logger.d(new User("kale", "male"));
// TODO: 2017/9/28 close log,change log lev
new Thread() {
@Override
public void run() {
@@ -59,17 +70,30 @@ public void run() {
}
}.start();
Logger.closeLog(); // close log
new User("kale", "male").show();
new Foo().print();
}
private void jsonTest() {
Logger.json(Dummy.SMALL_SON_WITH_NO_LINE_BREAK); // json
String j = "[" + Dummy.JSON_WITH_NO_LINE_BREAK + "," + Dummy.JSON_WITH_LINE_BREAK + "]";
Logger.json(j);
}
private static class User {
Logger.e("can you see me~!");
private String name;
Logger.openLog(Log.INFO);
private String sex;
Logger.i("googogogoog");
CrashHandler.getInstance().init(); // 崩溃检测处理器
User(String name, String sex) {
this.name = name;
this.sex = sex;
}
// setRes(123); // 模拟崩溃
void show() {
Logger.d("name:%s sex:%s", name, sex);
}
}
private void levTest() {
@@ -86,6 +110,7 @@ private void levTest() {
} catch (ClassNotFoundException e) {
Logger.e(e, "something happened"); // exception
}
Logger.w(Log.getStackTraceString(new Throwable()));
Logger.d("first\nsecond\nthird");
test();
@@ -95,80 +120,9 @@ private void test() {
Logger.d("just test");
}
private void objTest() {
// object
Logger.object(new User("jack", "f"));
// list
Logger.object(Arrays.asList("kale", "jack", "tony"));
// array
Logger.object(new String[]{"Android", "ios", "wp"});
double[][] doubles = {
{1.2, 1.6, 1.7, 30, 33},
{1.2, 1.6, 1.7, 30, 33},
{1.2, 1.6, 1.7, 30, 33},
{1.2, 1.6, 1.7, 30, 33}
};
Logger.object(doubles);
}
private void jsonTest() {
Logger.json(Dummy.SMALL_SON_WITH_NO_LINE_BREAK); // json
String j = "[" + Dummy.JSON_WITH_NO_LINE_BREAK + "," + Dummy.JSON_WITH_LINE_BREAK + "]";
Logger.json(j);
}
private void locationTest() {
Foo.foo(); // other class
new User("kale", "m").show();// Internal class
}
private void largeDataTest() {
for (int i = 0; i < 20; i++) {
Logger.d("No." + i);
}
}
///////////////////////////////////////////////////////////////////////////
// 内部类中打log测试
///////////////////////////////////////////////////////////////////////////
private static class User {
private String name;
private String sex;
User(String name, String sex) {
this.name = name;
this.sex = sex;
}
void show() {
Logger.d("name:%s sex:%s", name, sex);
}
}
///////////////////////////////////////////////////////////////////////////
// crash
///////////////////////////////////////////////////////////////////////////
/**
* 这里模拟后端给客户端传值的情况。
*
* 这里的id来自外部输入,如果外部输入的值有问题,那么就可能崩溃。
* 但理论上是不会有数据异常的,为了不崩溃,这里加try-catch
*/
private void setRes(@StringRes int resId) {
TextView view = new TextView(this);
try {
view.setText(resId); // 如果出现了崩溃,那么就会调用崩溃处理机制
} catch (Exception e) {
// 防御了崩溃
e.printStackTrace();
// 把崩溃的异常和当前的上下文通过log系统分发
Logger.e(e, "res id = " + resId);
}
}
}
@@ -0,0 +1,37 @@
package com.orhanobut.loggersample;
import android.util.Log;
import com.orhanobut.logger.LogAdapter;
import com.orhanobut.logger.helper.DefaultStyle;
import com.orhanobut.logger.helper.LogPrintHelper;
import com.orhanobut.logger.helper.LogSettings;
/**
* @author Kale
* @date 2017/9/28
*/
public class MyLogAdapter implements LogAdapter, LogPrintHelper.ILog {
private LogPrintHelper helper;
public MyLogAdapter(LogSettings settings) {
helper = new LogPrintHelper(settings, new DefaultStyle(), this);
}
@Override
public boolean isLoggable(int priority, String tag) {
return helper.isLoggable(priority, tag);
}
@Override
public void log(int priority, String tag, String message) {
tag = helper.getAutoTag(null);
helper.printLog(priority, tag, message, null);
}
@Override
public void println(int priority, String tag, String message, Throwable throwable) {
Log.println(priority, tag, message);
}
}
Oops, something went wrong.

0 comments on commit 9352ac6

Please sign in to comment.