代码拉取完成,页面将自动刷新
V2.X 的aar包均基于xlog2分支,其它分支均已废弃!
XLog.logcatConfig()
.setEnable(enable) // 允许打印logcat
.setTag("XShawn") // 使用自定义TAG
.setLevel(XLog.DEBUG) // logcat 输出等级,小于此等级的log不会打印
.setBorderEnable(true); // logcat显示边界
logfile初始化主要是为了设置文件输出引擎、文件名、文件路径等关键参数。
XLog.logfileConfig()
.setEnable(true) // 允许输出到文件
.setLevel(XLog.DEBUG) // 输出等级,小于此等级的log不会输出
.setStackTraceEnable(true) // 输出Caller信息
.setLogfileName(fileName) // 文件名
.setLogfileDir(fileDir) // 文件路径
.setEngine(new LogfileEngineImpl(context)); // 输出引擎
// 3. 打印日志
// 3.1 打印格式化信息
XLog.d("启动NFC数据读取界面,当前进程:%s", "main");
// 3.2 打印各种对象
XLog.d(intent);
XLog.e(new String[]{"1", "2", "3"})
有边界效果(默认关闭)
E/XLog: ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
E/XLog: ┃ MainActivity2.onCreate(MainActivity2.kt:40)
E/XLog: ┣━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━
E/XLog: ┃ android.content.Intent{
E/XLog: ┃ Action = Action
E/XLog: ┃ DataString = asdasdasd
E/XLog: ┃ Type = uri
E/XLog: ┃ ComponentInfo = {x.shawn.core.test/x.shawn.core.test.MainActivity2}
E/XLog: ┃ Identifier = Identifier
E/XLog: ┃ Flags = (1081344)|FLAG_ACTIVITY_CLEAR_TASK|FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
E/XLog: ┃ Extras = android.os.Bundle(4){
E/XLog: ┃ age = 30
E/XLog: ┃ data = [1, 2, 3, 4]
E/XLog: ┃ name = XShawn
E/XLog: ┃ message = android.os.Message{
E/XLog: ┃ what = 100
E/XLog: ┃ when = 1668482191081
E/XLog: ┃ arg1 = 111
E/XLog: ┃ arg2 = 222
E/XLog: ┃ obj = java.lang.ref.SoftReference<x.shawn.core.test.ABC{
E/XLog: ┃ abc = abcabc
E/XLog: ┃ inner = x.shawn.core.test.ABC$Inner{
E/XLog: ┃ a = x.shawn.core.test.A{
E/XLog: ┃ a = aaa
E/XLog: ┃ map = {k1={}, k2=22222, k3=v3} // 超出递归层数,直接toString的效果
E/XLog: ┃ set = []
E/XLog: ┃ }
E/XLog: ┃ ab = x.shawn.core.test.AB{
E/XLog: ┃ ab = ababab
E/XLog: ┃ }
E/XLog: ┃ iabc = iabc
E/XLog: ┃ }
E/XLog: ┃ }>
E/XLog: ┃ data = android.os.Bundle(0){}
E/XLog: ┃ target = Handler (android.os.Handler) {54ad477}
E/XLog: ┃ isAsynchronous = false
E/XLog: ┃ }
E/XLog: ┃ }
E/XLog: ┃ }
E/XLog: ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
有Caller信息(默认关闭显示,即下方 [MainActivity2.onCreate(MainActivity2.kt:40)]
部分)
[2022.11.15 11:15:19:584][main][E:XLog][MainActivity2.onCreate(MainActivity2.kt:40)] android.content.Intent{
Action = Action
DataString = asdasdasd
Type = uri
ComponentInfo = {x.shawn.core.test/x.shawn.core.test.MainActivity2}
Identifier = Identifier
Flags = (1081344)|FLAG_ACTIVITY_CLEAR_TASK|FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
Extras = android.os.Bundle(4){
age = 30
data = [1, 2, 3, 4]
name = XShawn
message = android.os.Message{
what = 100
when = 1668482119466
arg1 = 111
arg2 = 222
obj = java.lang.ref.SoftReference<x.shawn.core.test.ABC{
abc = abcabc
inner = x.shawn.core.test.ABC$Inner{
a = x.shawn.core.test.A{
a = aaa
map = {k1={}, k2=22222, k3=v3}
set = []
}
ab = x.shawn.core.test.AB{
ab = ababab
}
iabc = iabc
}
}>
data = android.os.Bundle(0){}
target = Handler (android.os.Handler) {c8e4113}
isAsynchronous = false
}
}
}
如需经常切换 Log 工具,或者需要降低 XLog 与其它代码的耦合,建议再封装一次。 封装时注意修改 method 偏移量,以免 StackTrace 信息输出错误:
XLog.logcatConfig()
.setEnable(enable)
.setMethodOffset(1) // 校准显示的方法名
.setBorderEnable(false);
此 library 基于如下开源项目衍生而来:
在此对 pengwei1024 大佬表示感谢!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
平台 | 地址 |
---|---|
语雀 | www.yuque.com/xshawn |
微信公号 |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型