Skip to content

Commit 3f60324

Browse files
committed
Support immediate print for EasyLog
1 parent dd22267 commit 3f60324

File tree

1 file changed

+19
-1
lines changed
  • utils/src/main/java/com/haoge/easyandroid/easy

1 file changed

+19
-1
lines changed

utils/src/main/java/com/haoge/easyandroid/easy/EasyLog.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class EasyLog private constructor(
1717
private val singleStyle: Format?,// 单行显示时的样式
1818
private val formatter: EasyFormatter){
1919
private var tag:String = ""
20+
private var immediate:Boolean = false
2021
/**
2122
* 设置一个临时的tag值。在下次调用d/i/v/w/e/wtf方法进行日志输出时。进行使用。
2223
*
@@ -26,6 +27,17 @@ class EasyLog private constructor(
2627
this.tag = tag
2728
return this
2829
}
30+
31+
/**
32+
* 指定是否使日志进行即时输出:即不讲打印任务派发到专属任务线程中,而是直接在当前线程进行打印。
33+
*
34+
* 使用后将自动置空。所以此immediate的作用域[只在下一次打印]
35+
*/
36+
fun immediate(immediate:Boolean): EasyLog {
37+
this.immediate = immediate
38+
return this
39+
}
40+
2941
/**
3042
* 格式化数据any并进行Log.d()打印
3143
*/
@@ -87,7 +99,13 @@ class EasyLog private constructor(
8799
val current = Thread.currentThread()
88100
val tag = if (tag.isEmpty()) trace.fileName else tag
89101
this.tag = ""
90-
EXECUTOR.execute { invoke.invoke(current, trace, tag) }
102+
if (immediate) {
103+
invoke.invoke(current, trace, tag)
104+
immediate = false
105+
} else {
106+
EXECUTOR.execute { invoke.invoke(current, trace, tag) }
107+
}
108+
91109
}
92110

93111
private fun print(message:String, trace: StackTraceElement, type:String, tag:String, callThread:Thread) {

0 commit comments

Comments
 (0)