2

We use grails.config.locations to pull in (optional) settings from a file external to the app. Is there a good way to detect that this file was loaded, either in Bootstrap.groovy or within Config.groovy itself?

Config.groovy has this:

grails.config.locations = [
  "file:${userHome}/.grails/${appName}-config.groovy"
]

It'd be nice to know if Grails found and read in this file.

Sean LeBlanc
  • 185
  • 2
  • 12
  • What is it that you want the program to do in response to knowing if the config file was read or not? – Jeff Scott Brown Sep 02 '15 at 02:26
  • Perhaps you can add a special and unique configuration in that file and check if that configuration exists where you want. If the configuration is found then the external config file has been loaded. – Ashraf Purno Sep 02 '15 at 04:51
  • It still isn't clear what them motivation is. If the functional requirement could be expressed, there are likely good solutions to the problem. – Jeff Scott Brown Sep 02 '15 at 13:32
  • Jeff - The goal would be to print something out to the console (as long as it is visible within IntelliJ's console, or if running via command-line, to see it there) that a file has been read in. That way, the developer would know this. – Sean LeBlanc Sep 02 '15 at 19:18

1 Answers1

0

You may be seeing this when turning Grails debug mode, but you don't want to do that. I am using the following strategy. First I check if the file exists:

 def externalConfigFile = "${userHome}/.grails/${appName}-config.groovy"
 if (new File(externalConfigFile).exists()) {
     grails.config.locations << "file:" + externalConfigFile
     log.info "External configuration file found at ${externalConfigFile} ..." 
 }

And then in the file itself I just log that it was run:

 log.info 'External config file was loaded.'

So now I can see in the logs upon startup that I found an external configuration file, it is an existing file, and the file was run by Grails, so it is loaded.

I haven't found anything better as yet.

Aston
  • 3,654
  • 1
  • 21
  • 18