以另一种颜色显示System.out.println输出 [英] Show System.out.println output with another color
问题描述
我有一个大项目来调试,我想知道是否还可以使用更改 System.out.println
方法在eclipse的输出
I have a big project to debug, and I was wondering if there is anyway I could use to change the System.out.println
method in the output of eclipse
例如:
System.out.println("I want this to be red");
System.out.println("I want this to be blue");
System.out.println("I want this to be yellow");
System.out.println("I want this to be magenta");
以提高可读性。
EDIT
with sysout我有这个
with sysout I have this
与syserr我有这个
with syserr I have this
推荐答案
code> System.err.println 你想要的行 - 我相信这是默认。 (您可以在偏好设置 - >运行/调试 - >控制台中更改它。)
Within Eclipse, the simplest approach would be to use System.err.println
for lines you want to be in red - I believe that's the default. (You can change it in Preferences -> Run/Debug -> Console).
当运行在 > console当然,但我不是认为eclipse控制台支持ANSI颜色转义序列等。
That difference won't show up when running in a real console of course, but I don't think the Eclipse console supports ANSI colour escape sequences etc.
编辑:对于Windows控制台,我希望 ANSI转义序列能正常工作。这不是非常便携的,但如果这不是一个问题,你可以创建一个类来适当地封装转义序列,所以你可以调用像:
For the Windows console, I'd expect ANSI escape sequences to work. It's not hugely portable, but if that's not a problem, you could just create a class to encapsulate the escape sequences appropriately, so you could call something like:
ansiConsole.printRed("sample line in red");
ansiConsole.printBlue("sample line in blue");
(我可能会让这些方法返回到每个调用之后的当前颜色。)
(I'd probably make those methods return back to whatever the "current" colour was after each call.)
EDIT:如评论中所述, Jansi 库已存在,所以你可以使用它。它没有上述方法,但我相信它仍然会做你想要的...
As noted in comments, the Jansi library already exists, so you might as well use that. It doesn't have the methods described above, but I'm sure it'll still do what you want...
这篇关于以另一种颜色显示System.out.println输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!