0

I have 2 problems about Grails logging and using external config file.
1. In src/groovy folder, I put a class A and I want to log events in some methods, but I can not use the built-in "logger", because this class is outside from service and controller scope of Grails application. I try to use LogFactory.getLog("A.class"), but I do not see anything write out from this logging variable. So how can I force this additional logger to write log in to the same log file which is created by default? Or is it possible to re-use the built-in logger provided by Grails?
2. I want to allow user to re-define some parameters which will be used in application, so I create an external configuration file and build the syntax of file content like the way Grails apply to messages resource files (code=value). So can I make Grails to understand and deal with that file as other message resource files? And how to include it to the resource classpath of application?
Thank you so much!

Đinh Hồng Châu
  • 5,300
  • 15
  • 53
  • 90
  • 1
    You should really post 2 questions since these are totally unrelated. I can answer #2 but I won't here because I can't answer #1. – Gregg Mar 22 '12 at 19:46

1 Answers1

0

Here's how to add a configuration file to a Grails project.

Create a properties file myExternalProperties.groovy and put it on your classpath (such as the $TOMCAT_HOME/lib directory).

Create a configuration file grails-app/conf/MyConfig.groovy to use the external configuration values (if needed). You will not be able to use the properties defined in myExternalProperties.groovy within grails-app/conf/Config.groovy.

Edit grails-app/conf/Config.groovy. Uncomment the lines the define grails.config.locations and add this:

grails.config.locations << "classpath:MyExternalProperties.groovy"
grails.config.locations << "classpath:MyConfig.groovy"

Add the following to scripts/Events.groovy (which probably needs to be created).

 eventCompileEnd = {
     ant.copy(todir:classesDirPath) {
         fileset(file:"${basedir}/grails-app/conf/MyConfig.groovy")
     }
 }

That last part is very important.

Big Ed
  • 1,056
  • 9
  • 20
  • And yet this answer can't honestly be accepted because you didn't answer his questionS. Dude needs to split them. – Gregg Mar 23 '12 at 03:01
  • That might be true, but the purpose of Stack Overflow is to help people solve their problems, and a partial answer is better than none at all. – Big Ed Mar 23 '12 at 13:08