Quantcast

Configuring log4j in Config.groovy appName not set

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Configuring log4j in Config.groovy appName not set

sethfuller
I have a Config.groovy with the first part of my log4j configuration block like this:

log4j = {

        appenders {
                console name: 'stdout', layout: pattern(conversionPattern: "%d [%t] %-5p %c %x - %m%n")
                rollingFile name: 'file1', maxFileSize: (10 * 1024 * 1024),  file:"${logDirectory}/${appName}-${grails.util.Environment.current.name}.log", layout: pattern(conversionPattern: "%d [%t] %-5p %c %x - %m%n")
        }

When I run a command I get an error that appName is not set, although earlier in Config.groovy in my environments block I have this which does work:

        development {
           grails.serverURL = "http://localhost:8080/${appName}"
    }

Any idea why appName is not set for log4j configuration, but is set for the environments configuration? Is there another variable I could use to get the application name?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Configuring log4j in Config.groovy appName not set

Ian Roberts
On 11/07/2012 15:48, sethfuller wrote:
> Any idea why appName is not set for log4j configuration, but is set for the
> environments configuration? Is there another variable I could use to get the
> application name?

The log4j closure gets evaluated separately from the rest of
Config.groovy, and doesn't have the same variables available to it.  I
believe grails.util.Metadata is usable within the closure, so try
Metadata.current.applicationName.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Configuring log4j in Config.groovy appName not set

longwa
We just worked around it by adding:

    def applicationName = appName

right above the log4j closure and then referencing applicationName in the closure.

On Wed, Jul 11, 2012 at 11:00 AM, Ian Roberts <[hidden email]> wrote:
On 11/07/2012 15:48, sethfuller wrote:
> Any idea why appName is not set for log4j configuration, but is set for the
> environments configuration? Is there another variable I could use to get the
> application name?

The log4j closure gets evaluated separately from the rest of
Config.groovy, and doesn't have the same variables available to it.  I
believe grails.util.Metadata is usable within the closure, so try
Metadata.current.applicationName.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Configuring log4j in Config.groovy appName not set

sethfuller
In reply to this post by Ian Roberts
Using Metadata.current.applicationName worked, thanks.
Loading...