当前位置: 首页 > news >正文

Android isLoggable定制属于自己的log

Android原生自带的 android.util.Log,其中有一个 isLoggable 方法的运用

    /** * Checks to see whether or not a log for the specified tag is loggable at the specified level.**  The default level of any tag is set to INFO. This means that any level above and including*  INFO will be logged. Before you make any calls to a logging method you should check to see*  if your tag should be logged. You can change the default level by setting a system property:*      'setprop log.tag.&lt;YOUR_LOG_TAG> &lt;LEVEL>'*  Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will*  turn off all logging for your tag. You can also create a local.prop file that with the*  following in it:*      'log.tag.&lt;YOUR_LOG_TAG>=&lt;LEVEL>'*  and place that in /data/local.prop.** @param tag The tag to check.* @param level The level to check.* @return Whether or not that this is allowed to be logged.* @throws IllegalArgumentException is thrown if the tag.length() > 23*         for Nougat (7.0) releases (API <= 23) and prior, there is no*         tag limit of concern after this API level.*/public static native boolean isLoggable(String tag, int level);

使用方法

private static final String TAG = "MY_TAG"; // 定义自己的日志TAG
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); // 日志开关void testLog(){// 通过开关日志输出if (DEBUG) {Log.d(TAG, "测试日志输出");}
}

 

需要打开日志开关的时候

# 打开日志输出
adb shell setprop log.tag.MY_TAG DEBUG# 关闭日志输出,这里 INFO > DEBUG,会导致isLoggable返回false
adb shell setprop log.tag.MY_TAG INFO
http://www.lryc.cn/news/119422.html

相关文章:

  • 【Spring Boot】构建RESTful服务 — 使用Swagger生成Web API文档
  • 【实战】 九、深入React 状态管理与Redux机制(五) —— React17+React Hook+TS4 最佳实践,仿 Jira 企业级项目(二十)
  • PHP傻瓜也能搭建自己框架
  • 为什么商业基础软件需要开源
  • 【自用】云服务器 使用 docker 搭建 HomeAssistant + MQTT 物联网平台
  • ABAP: SQL 多值查询
  • 分布式学习最佳实践:从分布式系统的特征开始
  • 第三章 图论 No.8最近公共祖先lca, tarjan与次小生成树
  • [Kubernetes]Kubeflow Pipelines - 基本介绍与安装方法
  • Sui网络的稳定性和高性能
  • RabbitMQ 安装教程
  • STM32F429IGT6使用CubeMX配置GPIO点亮LED灯
  • DOM的节点操作+事件高级+DOM事件流+事件对象
  • 云端剪切板,让你的数据同步无界
  • Location匹配与Rewrite重写
  • Docker源码阅读 - goland环境准备
  • 数据库信息速递 -- MariaDB 裁员后,前景不确定 (翻译)
  • 4.1 Windows终端安全
  • win10强制卸载奇安信天擎
  • npm常用命令
  • (一)创建型设计模式:4、原型模式(Prototype Pattern)
  • 【算法学习】高级班九
  • 数据安全加固:深入解析滴滴ES安全认证技术方案
  • Typescript第九/十章 前后端框架,命名空间和模块
  • LLM - argparse 解析脚本参数
  • 谈一谈在两个商业项目中使用MVI架构后的感悟
  • ApacheCon - 云原生大数据上的 Apache 项目实践
  • Git 代码分支规范
  • ATFX汇评:美7月通胀率数据基本符合预期,美指仍无法站稳103关口
  • 系统架构设计专业技能 · 软件工程(一)【系统架构设计师】