I want to use send log messages to hourly rolling files in my grails application. Here is how I have configured log4j in Config.groovy
appenders {
rollingFile name:"stacktrace",
file: "/tmp/logs/app.log",
conversionPattern: '%-5p %d{MM-dd HH:mm:ss} %m (%F:%L)'
appender new DailyRollingFileAppender(
name: "events",
datePattern: "'.'yyyy-MM-dd-HH:mm",
file: "/tmp/logs/app_events.log",
layout: pattern(conversionPattern: "%c{2} %m%n")
)
}
root {
error 'stacktrace'
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.springframework'
info events: "com.app.events", additivity: false
This is how I'm getting logger for events within com.app.events
package:
LOG = Logger.getLogger('events')
LOG.info("logging info")
I'm not sure what I'm missing here. I don't see any logs printed. If I add info 'events'
inside root, it works but logs from all packages also go inside app_events.log
which is not what I want. I only want logs from com.app.events
package to go in app_events.log.
The parts of the logging instructions line in Config.groovy are:
// "Logging Level" "Appender Name": "Logger Name", "Other Options"
info events: "com.app.events", additivity: false
And in where you retrieve your logger:
// LOG = Logger.getLogger("Logger Name")
LOG = Logger.getLogger('events')
So to have the events
appender receive package com.app.events
logging, change how you retrieve your logger to:
LOG = Logger.getLogger('com.app.events')
Maybe using error 'stacktrace'
in the root block is affecting log4j. The stacktrace appender is a special appender just for full stacktraces. Try adding another appender as your root appender and use that in place of 'stacktrace'
in your root block.
appenders {
appender new DailyRollingFileAppender(
name: "base",
datePattern: "'.'yyyy-MM-dd-HH:mm",
file: "/tmp/logs/app_events.log",
layout: pattern(conversionPattern: "%c{2} %m%n")
)
}
root {
error "base"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.