Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

android-studio - Android Studio / IntelliJ:在日志(或logcat)中突出显示自定义字符串(Android Studio / IntelliJ: Highlight custom strings in the log (or logcat))

Android and IntelliJ both have support for highlighting log messages based on the log level.

(Android和IntelliJ都支持根据日志级别突出显示日志消息。)

I'd like to go a step further and also highlight "my" classes, means classes from "my" packages - in a different way so that I can recognize them quickly in the log.

(我想更进一步,并突出显示“我的”类,即“我的”软件包中的类-以不同的方式,以便我可以在日志中快速识别它们。)

So I'd like to see an option where I can define a custom string and then give lines which contain this string a custom highlighting.

(因此,我想看到一个选项,可以在其中定义自定义字符串,然后为包含该字符串的行自定义突出显示。)

The "string" could be a package name, a debug string, or whatever.

(“字符串”可以是程序包名称,调试字符串等。)

Do you know if such a solution exists already?

(您知道这样的解决方案是否已经存在吗?)

Maybe there's already a plugin for that?

(也许已经有一个插件了?)

  ask by diskostu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not aware of anything specifically targeting this use case, but I have workarounds for you.

(我不知道有什么专门针对此用例的,但是我为您提供了解决方法。)

Search (搜索)

Focus the LogCat window by clicking into it and the press Ctrl+F , this brings up the local search bar and you can enter your package name:

(通过单击将焦点对准LogCat窗口,然后按Ctrl + F ,这将弹出本地搜索栏,您可以输入软件包名称:) 示例日志

Filter logs (过滤日志)

This solution is from my question: How can I disable Android's internal logging for specific tags (eg AbsListView, GestureDetector, endeffect) If you're having problems with spamming log lines you don't care about just filter them out, for example I have this configuration:

(该解决方案来自于我的问题: 如何禁用特定标签(例如AbsListView,GestureDetector,endeffect)的Android内部日志记录?如果您在发送垃圾邮件时遇到问题,则不必在乎仅过滤掉它们,例如,此配置:)

^(?!AbsListView|endeffect|GestureDetector|CustomFrequencyManager|ApplicationPackageManager|PersonaManager|ProgressBar|ViewRootImpl|MotionRecognitionManager)
^(?!Unable to resolve superclass of|Link of class|DexOpt: unable to opt direct call|Could not find class|Could not find method|VFY: )

日志过滤器

This leaves only the most important/relevant log lines:

(这仅留下最重要/相关的日志行:)

  • your app's logs

    (您应用的日志)

  • dalvikvm 's Garbage Collections

    (dalvikvm的垃圾回收)

  • StrictMode
  • and other unexpected things

    (和其他意外的事情)

High-level logging (高级日志记录)

I don't suggest you do this, included for completeness.

(我不建议您这样做,包括完整性。)

Use only Log.wtf and Log.e for your own logging and set colors/LogCat view's level filter accordingly.

(仅将Log.wtfLog.e用于您自己的日志记录,并相应地设置颜色/ LogCat视图的级别过滤器。)

This is not really useful if you want to have 5 levels of logging.

(如果您希望具有5个级别的日志记录,这并不是真正有用的。)

There may be some sneak-in log lines, but less than normal.

(可能会有一些偷偷摸摸的日志行,但比正常情况少。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...