Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2018-08-09- android.util.Log.md #26

Open
github-actions bot opened this issue May 22, 2023 · 0 comments
Open

2018-08-09- android.util.Log.md #26

github-actions bot opened this issue May 22, 2023 · 0 comments

Comments

@github-actions
Copy link

我是页眉


[正则匹配链接[]()语法上有局限性 , 如有疑虑可查看本文原文](https://github.com/TomGarden/tom-notes/blob/master/_posts/Collections/Android/Android_API_DOC/2018-08-09- android.util.Log.md)


layout: post
title: null
date: 2018-08-09 14:25:03 +0800
categories: jekyll update
author: Tom


目录

  • jekyll 的 kmarkdown 负责解析
    {:toc}


android.util.Log

API 用于打印日志。

通常一应该是用 Log.v(),log.d(),log.w(),log.e 和 log.e() 方法写日志。然后你可以在 Logcat 查看日志

日志的优先级顺序为:

  • V(VERBOSE) — 详细(最低优先级)
  • D(DEBUG) — 调试
  • I(INFO) — 信息
  • W(WARN) — 警告
  • E(ERROR) — 错误
  • A — 断言

除非在开发期间Verbose(详细信息)永远不应该编译到应用中。Debug日志在运行的应用中应该被除去。ERROR/WARNING应该永远保留在应用中。

提示:在应用中声明 TAG 是一个不错的实践,声明之后用该 TAG 作为参数调用日志方法。

//声明
private static final String TAG = "MyActivity";
//调用
Log.v(TAG, "index=" + i);

当你构建的字符串传递到 Log.d,编译器使用一个 StringBuilder 至少发生三次分配:StringBuilder 本身,缓冲区,String 对象。实际上还有另一次缓冲分配和复制,对于 GC 的压力更大。就是说,如果你的日志消息被过滤掉,将Android系统将做大量工作并产生大量开销。


我是页脚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants