Quantcast

Howto configure the location of the Grails log file outside Config.groovy?

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

Howto configure the location of the Grails log file outside Config.groovy?

marcopas
We are running our application on several Tomcat instances,
now the question arises if we can externalize the location of the
Grails log file.

The perfect solution would be that we can define where the log-files
should be written.
Any idea on how to tackle this? We wanted to use Config.groovy but the
sysadmin want
to have control on where the files will be written.

/Marco

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

jstell
Hi Marco

You could support an external config script. The external script would be evaluated and merged into your main config.
Check the docs: <a href="http://grails.org/doc/latest/guide/conf.html#3.4 Externalized Configuration">http://grails.org/doc/latest/guide/conf.html#3.4 Externalized Configuration

Jason


On Mon, Jan 23, 2012 at 11:54 AM, Marco Pas <[hidden email]> wrote:
We are running our application on several Tomcat instances,
now the question arises if we can externalize the location of the
Grails log file.

The perfect solution would be that we can define where the log-files
should be written.
Any idea on how to tackle this? We wanted to use Config.groovy but the
sysadmin want
to have control on where the files will be written.

/Marco

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

robelsner
In reply to this post by marcopas
Marco,

> The perfect solution would be that we can define where the log-files
> should be written.
> Any idea on how to tackle this? We wanted to use Config.groovy but the
> sysadmin want
> to have control on where the files will be written.

We set an environment variable, and have this code in our Config.groovy:

grails.config.locations = []
if (System.properties["${appName}.config.location"]) {
    grails.config.locations << "file:" +
System.properties["${appName}.config.location"]
}

So if -DappName=/path/to/file then that groovy file gets included.  In
that file is all of our log4j specific configuration, and server
specific configuration.

Rob

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

marcopas
Thanks Rob / Jason for your excellent suggestions!
I think that indeed including a separate config file for logging is a
good way to go.

There is one challenge for me in this case, the sysadmin should be
able to change the location of the logfile without
compiling the groovy files.. Maybe just giving the logfile location
using -DlogDirectory= would also be sufficient.

Any thoughts on that?

/Marco

2012/1/23 Rob Elsner <[hidden email]>:

> Marco,
>
>> The perfect solution would be that we can define where the log-files
>> should be written.
>> Any idea on how to tackle this? We wanted to use Config.groovy but the
>> sysadmin want
>> to have control on where the files will be written.
>
> We set an environment variable, and have this code in our Config.groovy:
>
> grails.config.locations = []
> if (System.properties["${appName}.config.location"]) {
>    grails.config.locations << "file:" +
> System.properties["${appName}.config.location"]
> }
>
> So if -DappName=/path/to/file then that groovy file gets included.  In
> that file is all of our log4j specific configuration, and server
> specific configuration.
>
> Rob
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

rpercy
This post has NOT been accepted by the mailing list yet.
In reply to this post by marcopas
If I understand you correctly, you want to move your logging configs out to an externalized log4j.properties file?

I was able to get this working using the instructions here: http://techbeats.deluan.com/how-to-use-an-external-log4jproperties-in-you-0 .  One extra step I don't think he mentions is: you'll need to run grails install-templates to generate the web.xml file.

On Mon, Jan 23, 2012 at 9:56 AM, marcopas [via Grails] <[hidden email]> wrote:
We are running our application on several Tomcat instances,
now the question arises if we can externalize the location of the
Grails log file.

The perfect solution would be that we can define where the log-files
should be written.
Any idea on how to tackle this? We wanted to use Config.groovy but the
sysadmin want
to have control on where the files will be written.

/Marco

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

    http://xircles.codehaus.org/manage_email





To unsubscribe from Grails - user, click here.
NAML

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

Re: Howto configure the location of the Grails log file outside Config.groovy?

Ian Roberts
In reply to this post by marcopas
On 23/01/2012 19:12, Marco Pas wrote:
> Thanks Rob / Jason for your excellent suggestions!
> I think that indeed including a separate config file for logging is a
> good way to go.
>
> There is one challenge for me in this case, the sysadmin should be
> able to change the location of the logfile without
> compiling the groovy files..

With Grails 2 you can specify several different log4j.something
closures, so you could put most of your log4j configuration in your
Config.groovy and then have an external config file to let the sysadmin
redefine the relevant file appenders:

// Config.groovy
grails.config.locations = // as per Rob's example
log4j.mainAppenders = {
  appenders {
    stdout ...
  }
}

log4j.fileAppenders = {
  appenders {
    file name:'fileAppender', file:'defaultLogfileForDev.txt'
  }
}

log4j.loggers = {
  root {
    ...
  }

  warn 'com.example.myapp'
}

// myapp-config.groovy (sysadmin to modify)
log4j.fileAppenders = {
  appenders {
    file name:'fileAppender', file:'/path/to/real/logfile.txt'
  }
}

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

Re: Howto configure the location of the Grails log file outside Config.groovy?

robelsner
In reply to this post by marcopas
> There is one challenge for me in this case, the sysadmin should be
> able to change the location of the logfile without
> compiling the groovy files.. Maybe just giving the logfile location
> using -DlogDirectory= would also be sufficient.
>
> Any thoughts on that?

Files included this way are compiled on the fly when loaded.

I found it helpful for our admin team if I included all the necessary
imports, etc, basically the skeleton, and then made some nice variable
names for them to update so they didn't have to hunt through groovy
code.

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

marcopas
So the groovy file actually gets compiled.. damn.. i never was aware of that!!
Great.. you guys made my day :)

2012/1/23 Rob Elsner <[hidden email]>:

>> There is one challenge for me in this case, the sysadmin should be
>> able to change the location of the logfile without
>> compiling the groovy files.. Maybe just giving the logfile location
>> using -DlogDirectory= would also be sufficient.
>>
>> Any thoughts on that?
>
> Files included this way are compiled on the fly when loaded.
>
> I found it helpful for our admin team if I included all the necessary
> imports, etc, basically the skeleton, and then made some nice variable
> names for them to update so they didn't have to hunt through groovy
> code.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

marcopas
Just wanted to let you guys know that we implemented your suggestions
and so far we are very happy with it! Thanks very much for your help!

2012/1/23 Marco Pas <[hidden email]>:

> So the groovy file actually gets compiled.. damn.. i never was aware of that!!
> Great.. you guys made my day :)
>
> 2012/1/23 Rob Elsner <[hidden email]>:
>>> There is one challenge for me in this case, the sysadmin should be
>>> able to change the location of the logfile without
>>> compiling the groovy files.. Maybe just giving the logfile location
>>> using -DlogDirectory= would also be sufficient.
>>>
>>> Any thoughts on that?
>>
>> Files included this way are compiled on the fly when loaded.
>>
>> I found it helpful for our admin team if I included all the necessary
>> imports, etc, basically the skeleton, and then made some nice variable
>> names for them to update so they didn't have to hunt through groovy
>> code.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>

---------------------------------------------------------------------
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

Re: Howto configure the location of the Grails log file outside Config.groovy?

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

Re: Howto configure the location of the Grails log file outside Config.groovy?

alex_masselot
we have adopted the following techniques on several projects.

It allows each developer to have his own config for dev mode, and the production database, and properties can set in production in the ~/${appName}-config.properties

def username = System.getProperty('user.name')

environments {
    production {
       grails.config.locations=[
          "file:${userHome}/${appName}-config.properties"
       ]
    }
    development {
grails {

        serverURL = "<a href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"

config.locations=[

"file:$username-dev.properties"

]

}
    }

    test {

        grails.serverURL = "<a href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"

    }



}


--
Alexandre Masselot
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re[2]: [grails-user] Re: Howto configure the location of the Grails log file outside Config.groovy?

michael astreiko
Re[2]: [grails-user] Re: Howto configure the location of the Grails log file outside Config.groovy?

Hello,


You also can try smth like:


def basePath = System.properties['base.dir']

def configPath = basePath + "/web-app"


environments {

    production {

        basePath = System.properties['catalina.base'] + "/webapps/${appName}"

        configPath = basePath

    }

    development {

    }

}


grails.config.locations = ["file:${configPath}/conf/AppConfig.groovy",

        "file:${configPath}/conf/AppConstants.groovy"]


So in development mode your config scripts are in 'web-app/conf' and in prod in 'tomcat/webapps/${appName}/conf'


Wednesday, January 25, 2012, 12:10:38 AM, you wrote:



we have adopted the following techniques on several projects.


It allows each developer to have his own config for dev mode, and the production database, and properties can set in production in the ~/${appName}-config.properties


def username = System.getProperty('user.name')


environments {

    production {

       grails.config.locations=[

          "file:${userHome}/${appName}-config.properties"

       ]

    }

    development {

grails {


        serverURL = "<a class=rvts7 href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"


config.locations=[


"file:$username-dev.properties"


]


}

    }


    test {


        grails.serverURL = "<a class=rvts7 href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"


    }




}



-- 

Alexandre Masselot



http://alexandre-masselot.blogspot.com/





-- 

Best regards,

Michael Astreiko

--------------------------------------------------------------------- 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

Re[2]: [grails-user] Re: Howto configure the location of the Grails log file outside Config.groovy?

michael astreiko
In reply to this post by alex_masselot
Re[2]: [grails-user] Re: Howto configure the location of the Grails log file outside Config.groovy?

Hello,


Sorry, it is about Config not logs.

But same for logs:


appenders {

        rollingFile name: 'file', maxFileSize: 5120000, file: "${basePath}/logs/yourName.log", maxBackupIndex: 10, layout: pattern(conversionPattern: '%d [%t] %-5p (%c) - %m%n'), encoding: 'UTF-8'

    }


Wednesday, January 25, 2012, 12:10:38 AM, you wrote:



we have adopted the following techniques on several projects.


It allows each developer to have his own config for dev mode, and the production database, and properties can set in production in the ~/${appName}-config.properties


def username = System.getProperty('user.name')


environments {

    production {

       grails.config.locations=[

          "file:${userHome}/${appName}-config.properties"

       ]

    }

    development {

grails {


        serverURL = "<a class=rvts7 href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"


config.locations=[


"file:$username-dev.properties"


]


}

    }


    test {


        grails.serverURL = "<a class=rvts7 href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"


    }




}



-- 

Alexandre Masselot



http://alexandre-masselot.blogspot.com/





-- 

Best regards,

Michael Astreiko

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Loading...