108

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.

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
Newtopian
  • 7,543
  • 4
  • 48
  • 71
  • you can use [MulticolorLayout](http://www.jcabi.com/jcabi-log/apidocs/com/jcabi/log/MulticolorLayout.html) from [jcabi-log](http://www.jcabi.com/jcabi-log), as explained here: http://stackoverflow.com/questions/7848325 – yegor256 Aug 30 '12 at 15:04
  • Interresting ! ANSI-Coloring, I should have a look at that next time I fire-up my Eclipse ! thanks. As for the JCabi I do like to contextualize my loggers and rarely that fits with the class name so I doubt a static wrapper would do the trick. I often need to dynamically set the name of the logger to the instance as it gives me much more efficient use of the logging info. – Newtopian Aug 30 '12 at 15:19

10 Answers10

81

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.*

Benjamin Seiller
  • 2,875
  • 2
  • 32
  • 42
  • 3
    The plugin doesn't seam to work with latest Eclipse (Helios). – sorin Sep 21 '11 at 09:20
  • 1
    correction about the plugin not being actively developed, I asked the creator a few questions and got replies within hours ! As for the patterns the plugin takes regular expressions so some tweaking and mucking around is expected when configuring it. I would recommend installing a regular expression plugin to try with copy pasted extracts from the console. Once configured though it works like a charm – Newtopian Dec 31 '11 at 02:13
  • @Newtopian is there a way i can contact the creator ? – Elye M. Apr 24 '13 at 16:26
  • 2
    In case anyone is looking for the documentation for the Grep Console: http://marian.schedenig.name/wp-content/static/grepconsole_userguide/ – Danny Bullis May 30 '18 at 17:05
  • 1
    Also, in case any one needs help with the regex patterns (this help link is also included in the Grep Console dialog in eclipse): https://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html – Danny Bullis May 30 '18 at 17:18
  • 1
    Please consider removing first [update] - now it can be easily installed via the Marketplace. – Line Oct 04 '18 at 09:07
19

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.

Community
  • 1
  • 1
fmjrey
  • 1,141
  • 1
  • 10
  • 16
  • I used webpage http://mihai-nita.net/2013/06/03/eclipse-plugin-ansi-in-console/. Perfeclty simple ansi support in console! – tutejszy Sep 12 '14 at 21:50
10

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)

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91
6

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

javanna
  • 59,145
  • 14
  • 144
  • 125
David Santamaria
  • 8,671
  • 7
  • 33
  • 43
5

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.

jajube
  • 319
  • 2
  • 5
4

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."

Neal Swearer
  • 2,482
  • 1
  • 16
  • 11
2

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

thSoft
  • 21,755
  • 5
  • 88
  • 103
  • 1
    thats the right way to do it, but i think the poster was hoping some one had done this for ansi escape sequences or html color codes. – aepurniet Sep 30 '09 at 05:08
1

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.

GHad
  • 9,611
  • 6
  • 34
  • 40
  • I have tried it a long time ago, it was very helpfull though I do not know if it can help me in this case. I expect it to enable me more granularity in how rows are colored, but I want more... I will try it tomorrow. – Newtopian Oct 24 '08 at 15:09
1

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

0

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.

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278