Ho to use xml or html layout with the Grails Log4j DSL

376 views Asked by At

I am traying to get log4j to log to file in XMLLayout using the groovy log4j dsl. However, it seems that the "layout:"-part is being ignored. This is my setup:

appenders {
    file name: 'fileAppender', layout: xml, file: '/tmp/logs/applog.xml', threshold: org.apache.log4j.Level.INFO
    console name: "stdout", threshold: org.apache.log4j.Level.INFO
}

root {
    debug 'stdout', 'fileAppender'
}

So to stdout I corectly get my info-level pattern layout, but in the file I also get pattern-layout...

What's the trick here?

2

There are 2 answers

0
Burt Beckwith On BEST ANSWER

This is a bug. I've fixed it for 2.0.1: http://jira.grails.org/browse/GRAILS-8635

The workaround as you found is to use the constructor explicitly instead of the DSL shortcut.

0
Julian On

Well I found out that you can just use layout: new XMLLayout() or layout: new HTMLLayout()

But still, in the documentation it says

By default the Log4j DSL assumes that you want to use a PatternLayout. However, there are other layouts available including:

xml - Create an XML log file
html - Creates an HTML log file
simple - A simple textual log
pattern - A Pattern layout

It seems to me that the shortcuts for xml and html don't work.