The following config.json won't work (run: loading initial config: loading new config: setting up default log: unrecognized log level: {env.LOG_LEVEL}), but it would be nice if it did:
{
"logging": {
"sink": {
"writer": {}
},
"logs": {
"default": {
"level": "{env.LOG_LEVEL}",
"encoder": {
"format": "json"
}
}
}
},
"apps": {
"http": {
"servers": {
"server-1": {
"listen": [":443"],
"routes": [
{
"match": [
{
"host": ["localhost"]
}
],
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "localhost:8080"
}
]
}
]
}
]
}
}
}
}
}
Especially when running in Docker or Kubernetes, it's common to configure applications via environment variables. Having the option to have a common base configuration which works as-is, but is still customizable, is very useful. One application could set LOG_LEVEL=debug and another LOG_LEVEL=info, but both could use the same config.json.
For the same reason, it could also be useful to support placeholders in the filename option of the file output module.
There might be other fields where placeholders can be useful, but those are the most useful ones, in my opinion.
No config.json reuse, each application has their own
--
This should be pretty easy to implement. Free game for anyone who would like to submit a PR!
Hi,
I want to implement this. I am thinking of using text/template when reading the config in loadConfig function. We can pass environment variables as a map to the template. So the above example would be written as {{ index . "LOG_LEVEL"}} instead of {env.LOG_LEVEL}
What do you think about this approach?
@iamd3vil Look into the Replacer funcs
@Mohammed90 Ohh, didn't know this existed. Seems pretty easy now. Will send a PR.
Thanks
@pascalgn Thanks to @iamd3vil's contributions, you can now use placeholders for log level and log filenames! Probably only useful for environment variable substitutions, but there ya have it. :)