Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coloring slf4j/log4j output in eclipse

I am trying to use logback-beagle in eclipse/kepler (java). As I understand it is not currently supported as listed below(?).

http://marketplace.eclipse.org/content/logback-beagle#.Uv1cGPldWK8

I still went ahead and installed the plugin and dont see it under windows-preferences. Is there an alternative to get similar functionality (of color coding and navigating from log output of slf4j/log4j in eclipse) Or can I make beagle plugin work for eclipse(?). I dont understand why eclipse want to have it in marketplace, but doesnt show up in preferences after installing

like image 559
kashili kashili Avatar asked Feb 14 '14 00:02

kashili kashili


1 Answers

I just came across the same issue, and it seems that logback-beagle simply does not work in kepler. I believe it works in earlier versions of eclipse but following the installation instructions from http://logback.qos.ch/beagle/ and trying a few other things (like the colouring options for logback with JAnsi) led me nowhere.

The best alternative I've found (since you asked for one) is Grep Console, which works with my kepler installation and is very configurable to allow you to apply regex-based colouring condtions on your console output.

As for your "navigating from log output" point, which I'm assuming means you want to be able to click on a (Java) class name and automagically navigate to the corresponding class definition, you simply need to configure your console appender to include the output for file and line number, i.e. (%file:%line) (or %F and %L if you prefer; see the pattern layout options for more details). For instance, here's what I'm using in my logback.xml file:

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%-5level %d{dd/MM/yyyy HH:mm:ss.SSS} \(%file:%line\) - %message%n</pattern>
    </encoder>
</appender>

The only issue with using both Grep Console and the file-line-pattern is that the Grep Console's styling of lines hides the fact that the class name and line number is clickable (the Grep Console style overrides eclipse's blue underlining of the "link"). I guess if you want the "link style", you have to work around it by configuring a pattern in the Grep Console to recognise these links and style them yourself.

Edit: Just because it bugged me not to see the linked Java classes, I used the following pattern to "linkify" the Java classes and line numbers:

([a-zA-Z]+\.java:\d+)

I added an expression in the "Manage Expressions" dialog, called it "Java link", used the above regex pattern, and styled it to use no style for "Whole line" (i.e. it will inherit the style based on the log level) and defined "Group 1" style as blue (#0000ff) foreground colour and blue underlining, with a pale blue background (#c0ffff) so that it will override the background colour of the remainder of the line:

Edit expression screenshot

like image 118
Amos M. Carpenter Avatar answered Nov 20 '22 09:11

Amos M. Carpenter