赞
踩
一个适应于Java/Kotin项目日志打印工具库,同时支持在安卓和PC机使用,同时也支持跨进程收集数据
基础功能有:
高级功能有:
根目录gradle文件下配置
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
应用目录gradle文件下配置依赖
implementation 'com.github.worson:AwesomeLog:0.1'
此方法会自适应运行平台
fun initConsolePrint(debug:Boolean){
L.init(
LogConfiguration.Builder()
.logLevel(if (debug) LogLevel.ALL else LogLevel.DEBUG)
.threadInfo(debug)
.traceInfo(debug, 7)
.addPrinter(Platform.get().defaultPrinter())
.build()
)
}
fun initFileLog(context: Context,debug:Boolean=true) { var filePrinter: Printer?=null var logHandler: ZipLogHandler?=null var logUploader: LogFileReporter?=null val logPath = File(context.cacheDir,"log") L.init( LogConfiguration.Builder() .logLevel(if (debug) LogLevel.ALL else LogLevel.DEBUG) .threadInfo(true) .traceInfo(debug) .addPrinter(Platform.get().defaultPrinter()) .addPrinter( FilePrinter.Builder( File(logPath.absolutePath, "logging").absolutePath ) .fileNameGenerator(DateFileNameGenerator()) .logHandler( ZipLogHandler( File(logPath.absolutePath, "backup").absolutePath, limitSize = 100 * 1024 * 1024, reporter = logUploader ).apply { logHandler=this } ) .build().apply { filePrinter = this } ) .build() ) filePrinter?.let { SocketSeverPrinterProxy(it).start() } }
L.i(TAG, "onCreate: ")
打印日志,lamda方法在过滤日志可减少性能消耗
L.d(TAG) {"onCreate: "}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。