Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.89 KB

log.md

File metadata and controls

67 lines (46 loc) · 1.89 KB

Log

Translations: 简体中文

The log of Sketch is provided by the Logger component, and the tag is unified as Sketch

Modify Level

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()