No application logging from Grails application?

2.5k Views Asked by At

I have a simple grails app and some logging in the controller. However, no matter how I configure the logging, I do not see my application log message (even though I can be overwhelmed with grails internal logging).

Config:

// log4j configuration
log4j = {
    // Example of changing the log pattern for the default console appender:
    //
    appenders {
        console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
        file name:'file', file:'C:\\Users\\C.Ross\\Logs\\Budget.log'
    }
    root {
        warn 'file', 'stdout'
    }

    warn  '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.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping',        // URL mapping
           'org.codehaus.groovy.grails.commons',            // core / classloading
           'org.codehaus.groovy.grails.plugins',            // plugins
           'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
           'org.springframework',
           'org.hibernate',
           'net.sf.ehcache.hibernate'

    trace 'grails.app.controller'

}

I've also tried

trace 'com.ross.budget'

and

root {
    all 'file', 'stdout'
}

But no luck at all. Even when everything else is logging I do not see the log messages from my app at all. What am I doing wrong?

Code:

 package com.ross.budget

 class BudgetController {

    def index() { 
        redirect(action:"list")
    }

    def list() {
        log.trace "Retrieving all budgets..."
        [budgetList: Budget.all]
    }

    def add() {
        log.trace "Calling add..."
    }

    def show(){
        log.trace "Retrieving budget"
        def budget = Budget.get(params.id)
        [budget: budget]
    }

    def save(){
        log.debug "Creating new budget"
        def budget = new Budget(params)
        budget.save()
        redirect(action:"list")
    }

    def addLineItem(){
        log.trace("Retrieving budget $params.id")
        def budget = Budget.get(params.id)
        log.trace("Creating line item from params")
        def lineItem = new LineItem(params)
        log.debug "Adding line item to budget"
        budget.lineItems.add(lineItem)
        log.trace "Saving budget"
        budget.save()
        log.trace("Redirecting to show ...")
        redirect(action:"show", id:params.id)
    }
}
1

There are 1 best solutions below

0
On

According to the Grails docs (under Configuring loggers), you need grails.app.controllers. Just make the artefact name plural.