如何将输出写入 Android 中的日志? [英] How do I write outputs to the Log in Android?

查看:41
本文介绍了如何将输出写入 Android 中的日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一些调试输出到日志中,用logcat查看.

I want to write some debugging output to the log to review it with logcat.

如果我向 System.out 写了一些东西,这已经在 logcat 中显示了.

If I write something to System.out this is already displayed in logcat.

写入日志并向输出添加级别和标签的干净方法是什么?

What is the clean way to write to the log and add levels and tags to my output?

推荐答案

查看 android.util.Log.它允许您以各种日志级别写入日志,并且您可以指定不同的标签来对输出进行分组.例如

Look into android.util.Log. It lets you write to the log with various log levels, and you can specify different tags to group the output. For example

Log.w("myApp", "no network");

将输出带有标签 myApp 和消息 no network 的警告.

will output a warning with the tag myApp and the message no network.

这篇关于如何将输出写入 Android 中的日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆