在 Eclipse 控制台中对日志进行着色

发布于 2024-07-08 01:09:47 字数 487 浏览 11 评论 0原文

有没有办法在 Eclipse 控制台中对部分日志进行着色。 我知道我可以发送到错误和标准流并对它们进行不同的着色,但我更喜欢在 ANSI 转义代码(或任何其他,HTML?)行中查找一些内容,我可以在字符串中嵌入颜色以使其在字符串中着色日志。

它肯定有助于使重要的部分脱颖而出,而无需诉诸奇怪的布局,而是将布局保留在 log4j 设置中,

这是我正在寻找的示例:

[INFO] 网格已完成....... < 。

如果粗体部分为蓝色,则这种颜色可以在一定程度上由应用程序控制 像这样(标签是概念性的和任意的,但你明白了):

log.info(String.format("网格已完成....... %s<代码>", isComplete ));


更一般地说,它是在日志中嵌入元信息以帮助呈现这些日志的能力。 就像我们标记网页内容以帮助通过 CSS 呈现信息一样。

Is there a way to colorize parts of logs in the eclipse console. I know I could send to error and standard streams and color them differently but I'm more looking someting in the lines of ANSI escape codes (or anyother, HTML ?) where I could embed the colors in the string to have it colored in the logs.

It sure would help making the important bits stand out without resorting to weird layout, rather keep the layout to the log4j setups

here is an example of what I am looking for :

[INFO ] The grid is complete ....... false

where the bold parts would be in blue, this coloring can be controlled by the application to an extent. like so (tags are conceptual and arbitrary, but you get the idea):

log.info(String.format("The grid is complete ....... <blue>%s</blue>", isComplete ));


On a more general note it is the ability to embed meta information in the logs to help the presentation of these logs. Much like we tag web pages content to help the presentation of the information by CSS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

一生独一 2024-07-15 01:09:48

尝试一下这个 Eclipse 插件:Grep Console

[更新]
正如评论者所指出的:
在当前最新版本的 Eclipse 中安装 Grep Console 时,您需要在安装对话框中取消选中“按类别分组项目”才能查看可用的项目。

正如 @Line 所指出的,该插件现在可以通过以下方式轻松安装再次访问 Eclipse Marketplace,无需更改任何选项。

[更新 2]
正如 @azdev 所指出的,要获得正确的突出显示:

仅输入文字字符串是行不通的。 要使线条着色,您必须将字符串括起来
<代码>.*
两边,像这样:
.*错误。*

Have a try with this Eclipse Plugin: Grep Console

[Update]:
As pointed out by commenters:
When installing Grep Console in the currently last version of Eclipse, you need to uncheck 'Group items by category' in the Install dialog to see the available items.

As pointed out by @Line the plugin can now be easily installed via the Eclipse Marketplace again without changing any options.

[Update 2]:
As pointed out by @azdev, to get proper highlighting:

Entering just literal strings doesn't work. To get a line to be colored, you have to enclose the string in
.*
on either side, like so:
.*ERROR.*

恰似旧人归 2024-07-15 01:09:48

实际上 ANSI 控制台插件 为 Eclipse 控制台添加了 ANSI 转义码支持。
但目前它确实有一个限制,跨多行的转义代码在滚动时会错误地泄漏到其他行,请参阅 问题#3

否则一些终端视图插件,如 中所述对于某些人来说,另一个问题可能是一个选择。

Actually the ANSI Console plugin adds ANSI escape code support to Eclipse console.
At present it does have a limitation though, whereby escape codes that span multiple lines leak incorrectly to other lines when scrolling, see issue #3.

Otherwise some terminal view plugin as explained in this other question might be an option for some.

妄司 2024-07-15 01:09:48

正如 @Benjamin Grep Console 已经指出的那样,它是在控制台中对输出进行着色的好方法。

我制作了一个简短的视频来演示它是如何工作的,并收到了 Grep 控制台插件的创建者的回复。 他提到 Grep console 3 已经发布。

屏幕截图 http://www.youtube.com/watch?v=fXjgGZAxToc

更新站点

Grep Console 2
http://eclipse.musgit.com
(需要 Eclipse 3.4 (Ganymede) 或更高版本以及 Java 5.0 或更高版本)

Grep Console 3
http://eclipse.schedenig.name
(需要 Eclipse 3.7 (Indigo) 或更高版本以及 Java 6.0 或更高版本)

As already pointed out by @Benjamin Grep Console is a great way to colorize output in the Console.

I had made a short video to demonstrate how it worked and heard back from the Creator of the Grep Console plugin. He mentioned that Grep console 3 is has been released.

Screen cast : http://www.youtube.com/watch?v=fXjgGZAxToc

Update Sites

Grep Console 2
http://eclipse.musgit.com
(requires Eclipse 3.4 (Ganymede) or higher and Java 5.0 or higher)

Grep Console 3
http://eclipse.schedenig.name
(requires Eclipse 3.7 (Indigo) or higher and Java 6.0 or higher)

音盲 2024-07-15 01:09:48

使用 Logback 及其 属性转换器 并将所有内容记录在 log4j 中,这可以让您看到不同颜色的不同级别。

祝你好运!

编辑eclipse 插件

What about use Logback and its property converter and log everything in log4j, that may allow you see the differents levels on differents colors.

Good luck!

EDIT: the eclipse plugin

黯然 2024-07-15 01:09:48

您可以在控制台插件中使用 ANSI Escape 对于 Eclipse。 您将需要它,以便 Eclipse 控制台可以解释 ANSI 转义代码。 安装它并重新启动 Eclipse
然后您可以使用 ANSI 颜色代码以某种颜色书写。 这是 ANSI 颜色代码列表< /a> 来自另一个 stackoverflow 答案。 然后你可以这样做:

public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_RED = "\u001B[31m";

public static void main(String[] args) {
    System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
}

我用它为控制台处理程序创建了一个自定义格式化程序,以便它以不同的颜色显示不同级别的记录器日志(信息日志为青色,警告日志为黄色,严重日志为红色)。 如果您有兴趣,这是我的做法

You can use ANSI Escape in Console plugin for Eclipse. You'll need this so the Eclipse console can interpret ANSI Escape codes. Install it and restart Eclipse.
Then you can use ANSI Color Codes to write in a certain color. Here's a list of ANSI Color Codes from another stackoverflow answer. Then you can do this:

public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_RED = "\u001B[31m";

public static void main(String[] args) {
    System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
}

I used this to create a Custom Formatter for the Console Handler so it shows logs from Logger in different levels with different colors (INFO logs in cyan, WARNING logs in yellow and SEVERE logs in red). Here's how I did it, if you're interested.

南城追梦 2024-07-15 01:09:48

我工作的地方使用 Ganymede Eclipse 插件,效果很好。

http://sourceforge.net/projects/ganymede/

“一个 Eclipse 的 log4j 插件,其工作原理类似到链锯(SocketServer)。包括颜色、过滤、详细信息并保存设置。”

We use the Ganymede Eclipse plugin where I work, and it works well.

http://sourceforge.net/projects/ganymede/

"A log4j plugin to Eclipse that works similar to chainsaw (SocketServer). Includes color, filtering, detailed information, and saves settings."

-小熊_ 2024-07-15 01:09:48

了解 org.eclipse.ui.console.consolePatternMatchListeners 扩展点。

Read about the org.eclipse.ui.console.consolePatternMatchListeners extension point.

一曲爱恨情仇 2024-07-15 01:09:48

您可以考虑尝试 Apache Chainsaw (http://logging.apache.org/chainsaw/index.html )如果您已经在使用 log4j。 允许您定义颜色和过滤器并使用(几乎)零配置。

You may consider trying Apache Chainsaw (http://logging.apache.org/chainsaw/index.html) if you are already working with log4j. Lets you define colors and filtern and works with (nearly) zero configuration.

初见终念 2024-07-15 01:09:48

我以前使用过这个插件,它可以让您根据自定义的正则表达式对日志行进行着色。

例如,当我使用它时,任何带有错误字样的行都将是红色的,警告将是橙色的,信息将是蓝色的......等等。

因为它是正则表达式,所以你可以做任何事情。 将其设置为每当以“>>>”开头时该行就变为绿色 然后在消息字符串前面加上“>>>”。

http://sourceforge.net/projects/logfiletools

I've used this plugin before, it lets you colourize lines of the log based on customized regex.

For example, when I was using it, any lines with the words error would be red, warning would be orange, info would be blue... etc.

Since it's regex, you could do anything. Set it up to make the line green whenever it starts with ">>>" and then prepend your message string with ">>>".

http://sourceforge.net/projects/logfiletools

不必了 2024-07-15 01:09:48

表情符号

您可以像其他人在答案中提到的那样使用文本颜色。

但您可以使用表情符号来代替! 例如,您可以使用 ⚠️ 作为警告消息,使用

Emoji

You can use colors for text as others mentioned in their answers.

But you can use emojis instead! for example you can use You can use ⚠️ for warning messages and ???? for error messages to make them standing out!

Or simply use these note books as a color:

????: error message
????: warning message
????: ok status message
????: action message
????: canceled status message
????: Or anything you like and want to recognize immediately by color

I personally use meaningful emojis for different outputs.

Authentication Key: ???? 
Server Error: ????
etc.

???? Bonus:

This method also helps you to quickly scan and find logs directly in the source code.

But linux default emoji font is not colorful by default and you may want to make them colorful, first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文