AndoridStuido 设置Log快捷键

本文介绍了如何在Android Studio中设置Log的快捷键,包括初始化步骤、配置相关文件如logback,并详细讲解了所需的依赖配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template name="logd" value="mLogger.debug(&quot;$METHOD$: $VAR$={}&quot;, $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(&quot;$METHOD$: $VAR$={}, $VAR1$={}&quot;, $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(&quot;$METHOD$: $VAR$={}, $VAR1$={}, $VAR2$={}&quot;, $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(&quot;LOG:$CLASS$:$METHOD$&quot;, $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(&quot;LOG:$CLASS$:$METHOD$ $VAR1$={}&quot;, $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(&quot;LOG:$CLASS$:$METHOD$ $VAR$={}&quot;, $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(&quot;LOG:$CLASS$:$METHOD$ $VAR$={} $VAR2$={}&quot;, $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(&quot;LOG:$CLASS$:$METHOD$ $VAR$={} $VAR2$={} $VAR3$={}&quot;, $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(&quot;LOG:$CLASS$:$METHOD$ $VAR$={} thread={}&quot;, $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()

        // 注册变量到xml里
        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'
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值