I'm trying to use log4j from my src/groovy class in grails project like this:
package com.brand.vh.importer.command
import org.apache.log4j.Logger
class NewOrder extends CommandAbstract {
private final Logger log = Logger.getLogger(getClass())
NewOrder() {
log.debug("NewOrder constructor called")
}
}
In Config.groovy I have the following log4j settings:
....
// log4j configuration
import org.apache.log4j.DailyRollingFileAppender
log4j = {
appenders {
appender new DailyRollingFileAppender(
name: "fileAppenderImporter",
file: "log/importer.log",
datePattern: "'.'yyyy-MM-dd",
layout: pattern(
conversionPattern:
"%d{ISO8601} [%p][%X{IP}](%F:%M:%L):%n%m%n%n"
)
)
....
}
...
debug additivity: false,
fileAppenderImporter: ["com.brand.vh.importer"]
...
}
But my log/importer.log is always empty. What's wrong with my code/config?
I will be glad to any advice, links etc
I wonder if you have your parameters out of order.
This works for me:
log4j = {
appenders {
console name: 'stdout', layout: pattern(conversionPattern: '%d [%t] %-5p [%c(%F:%L)] - %m%n')
appender new DailyRollingFileAppender(
name: "fileAppenderImporter",
file: "log/importer.log",
datePattern: "'.'yyyy-MM-dd",
layout: pattern(
conversionPattern:
"%d{ISO8601} [%p][%X{IP}](%F:%M:%L):%n%m%n%n"
)
)
}
root {
debug 'stdout'
info 'stdout'
additivity = false
}
debug fileAppenderImporter: ['com.brand.vh.importer'], additivity: false
}
With your same code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With