<template name="logd" value="mLogger.debug("$METHOD$: $VAR$={}", $VAR$)" description="Log.debug(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
<option name="KOTLIN_STATEMENT" value="false" />
</context>
</template>
<template name="logdd" value="mLogger.debug("$METHOD$: $VAR$={}, $VAR1$={}", $VAR$, $VAR1$)" description="Log.debug(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR1" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
<template name="logddd" value="mLogger.debug("$METHOD$: $VAR$={}, $VAR1$={}, $VAR2$={}", $VAR$, $VAR1$, $VAR2$)" description="Log.debug(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR1" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR2" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
<template name="loge" value="mLogger.error("LOG:$CLASS$:$METHOD$", $VAR$)" description="Log.e(TAG, String, Exception)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="false" />
<context />
</template>
<template name="logee" value="mLogger.error("LOG:$CLASS$:$METHOD$ $VAR1$={}", $VAR1$, $VAR2$)" description="Log.e(TAG, String, Exception)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR1" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR2" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logi" value="mLogger.info("LOG:$CLASS$:$METHOD$ $VAR$={}", $VAR$)" description="Log.i(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
<option name="KOTLIN_STATEMENT" value="false" />
</context>
</template>
<template name="logii" value="mLogger.info("LOG:$CLASS$:$METHOD$ $VAR$={} $VAR2$={}", $VAR$, $VAR2$)" description="Log.i(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR2" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
<template name="logiii" value="mLogger.info("LOG:$CLASS$:$METHOD$ $VAR$={} $VAR2$={} $VAR3$={}", $VAR$, $VAR2$, $VAR3$)" description="Log.i(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR2" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR3" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
<template name="logit" value="mLogger.info("LOG:$CLASS$:$METHOD$ $VAR$={} thread={}", $VAR$, Thread.currentThread())" description="Log.i(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
<template name="logt" value="private val mLogger: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(this.javaClass)" description="A static logtag with your current filename" toReformat="true" toShortenFQNames="false">
<context>
<option name="KOTLIN_OBJECT_DECLARATION" value="false" />
<option name="KOTLIN_TOPLEVEL" value="false" />
</context>
</template>
初始化
fun init() {
val mContext:Context = this
val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext
loggerContext.reset()
loggerContext.putProperty("CACHE_DIR", mContext.externalCacheDir!!.path)
val logbackConfigurationFile = File(mContext.getExternalFilesDir("configs"), "logback.xml")
mContext.assets.open("configs/logback.xml").use {
logbackConfigurationFile.writeText(it.reader(charset = Charsets.UTF_8).readText())
}
val joranConfigurator = JoranConfigurator()
joranConfigurator.context = loggerContext
joranConfigurator.doConfigure(logbackConfigurationFile)
}
配置文件
logback
依赖
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'com.github.tony19:logback-android:2.0.0'