coloring slf4j/log4j output in eclipse

我怕爱的太早我们不能终老 提交于 2019-12-07 01:04:06

问题


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


回答1:


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:



来源:https://stackoverflow.com/questions/21768299/coloring-slf4j-log4j-output-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!