Translations: 简体中文
The log of Sketch is provided by the Logger component, and the tag is unified as Sketch
Like most logging frameworks, Logger also controls the level of output logs through Logger
.Level, which defaults to Info
You can modify the level at any time, as follows:
// When initializing Sketch
Sketch.Builder(context).apply {
logger(level = Logger.Level.Debug)
}.build()
// At any other time
context.sketch.logger.level = Logger.Level.Debug
Tip
Excessive logs will affect UI fluency. For the official release version, please set the level to Info and above.
Logger Output logs through the Logger.Pipeline interface, on the Android platform Logger .Pipeline The implementation is AndroidLogPipeline, on non-Android platforms it is PrintLogPipeline
You can implement the Logger.Pipeline interface to customize new output, and then use it when initializing Sketch, as follows:
class MyPipeline : Logger.Pipeline {
override fun log(level: Logger.Level, tag: String, msg: String, tr: Throwable?) {
if (tr != null) {
val trString = tr.stackTraceToString()
println("$level. $tag. $msg. \n$trString")
} else {
println("$level. $tag. $msg")
}
}
override fun flush() {
}
override fun toString(): String = "MyPipeline"
}
Sketch.Builder(context).apply {
logger(pipeline = MyPipeline())
}.build()