Merge pull request #420 from cocap10/fixes-log

log info about TOML configuration file using
This commit is contained in:
Vincent Demeester 2016-05-30 17:48:00 +02:00
commit 2bd95620a5
5 changed files with 28 additions and 17 deletions

View file

@ -89,7 +89,7 @@ You can access to a simple HTML frontend of Træfik.
- The simple way: grab the latest binary from the [releases](https://github.com/containous/traefik/releases) page and just run it with the [sample configuration file](https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml): - The simple way: grab the latest binary from the [releases](https://github.com/containous/traefik/releases) page and just run it with the [sample configuration file](https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml):
```shell ```shell
./traefik -c traefik.toml ./traefik --configFile=traefik.toml
``` ```
- Use the tiny Docker image: - Use the tiny Docker image:

View file

@ -14,7 +14,7 @@ import (
// TraefikConfiguration holds GlobalConfiguration and other stuff // TraefikConfiguration holds GlobalConfiguration and other stuff
type TraefikConfiguration struct { type TraefikConfiguration struct {
GlobalConfiguration GlobalConfiguration
ConfigFile string `short:"c" description:"Timeout in seconds. Duration to give active requests a chance to finish during hot-reloads"` ConfigFile string `short:"c" description:"Configuration file to use (TOML)."`
} }
// GlobalConfiguration holds global configuration (with providers, etc.). // GlobalConfiguration holds global configuration (with providers, etc.).

8
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 660249b4d5cbcfd0cb0a2d9d39ce798ec8df7d3277c53ed4043fe2f61b29eeb9 hash: 1d42530971835a5a1e593e8efc54f28f2714cb8d1dfcb333e3b9ba92ef1917cc
updated: 2016-05-27T09:59:17.855890752+02:00 updated: 2016-05-30T16:53:17.058435869+02:00
imports: imports:
- name: github.com/boltdb/bolt - name: github.com/boltdb/bolt
version: dfb21201d9270c1082d5fb0f07f500311ff72f18 version: dfb21201d9270c1082d5fb0f07f500311ff72f18
@ -18,7 +18,7 @@ imports:
- name: github.com/codegangsta/negroni - name: github.com/codegangsta/negroni
version: ffbc66b612ee3eac2eba29aedce4c3a65e4dd0a1 version: ffbc66b612ee3eac2eba29aedce4c3a65e4dd0a1
- name: github.com/containous/flaeg - name: github.com/containous/flaeg
version: c425b9d758df1864ca838dbd433f1cf8f5097d51 version: a208db24c0e580be76efed167736fe3204c7c954
- name: github.com/containous/oxy - name: github.com/containous/oxy
version: 183212964e13e7b8afe01a08b193d04300554a68 version: 183212964e13e7b8afe01a08b193d04300554a68
subpackages: subpackages:
@ -29,7 +29,7 @@ imports:
- stream - stream
- utils - utils
- name: github.com/containous/staert - name: github.com/containous/staert
version: ff272631ecfc9c22490b651fea0f08d364d46518 version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4
- name: github.com/coreos/etcd - name: github.com/coreos/etcd
version: c400d05d0aa73e21e431c16145e558d624098018 version: c400d05d0aa73e21e431c16145e558d624098018
subpackages: subpackages:

View file

@ -8,7 +8,7 @@ import:
- package: github.com/cenkalti/backoff - package: github.com/cenkalti/backoff
- package: github.com/codegangsta/negroni - package: github.com/codegangsta/negroni
- package: github.com/containous/flaeg - package: github.com/containous/flaeg
version: c425b9d758df1864ca838dbd433f1cf8f5097d51 version: a208db24c0e580be76efed167736fe3204c7c954
- package: github.com/containous/oxy - package: github.com/containous/oxy
subpackages: subpackages:
- cbreaker - cbreaker
@ -18,7 +18,7 @@ import:
- stream - stream
- utils - utils
- package: github.com/containous/staert - package: github.com/containous/staert
version: ff272631ecfc9c22490b651fea0f08d364d46518 version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4
- package: github.com/docker/engine-api - package: github.com/docker/engine-api
version: 3d3d0b6c9d2651aac27f416a6da0224c1875b3eb version: 3d3d0b6c9d2651aac27f416a6da0224c1875b3eb
subpackages: subpackages:

View file

@ -73,15 +73,9 @@ Complete documentation is available at https://traefik.io`,
if _, err := s.LoadConfig(); err != nil { if _, err := s.LoadConfig(); err != nil {
fmtlog.Println(err) fmtlog.Println(err)
} }
if traefikConfiguration.File != nil && len(traefikConfiguration.File.Filename) == 0 {
// no filename, setting to global config file traefikConfiguration.ConfigFile = toml.ConfigFileUsed()
log.Debugf("ConfigFileUsed %s", toml.ConfigFileUsed())
traefikConfiguration.File.Filename = toml.ConfigFileUsed()
}
if len(traefikConfiguration.EntryPoints) == 0 {
traefikConfiguration.EntryPoints = map[string]*EntryPoint{"http": {Address: ":80"}}
traefikConfiguration.DefaultEntryPoints = []string{"http"}
}
if err := s.Run(); err != nil { if err := s.Run(); err != nil {
fmtlog.Println(err) fmtlog.Println(err)
os.Exit(-1) os.Exit(-1)
@ -107,6 +101,23 @@ func run(traefikConfiguration *TraefikConfiguration) {
} }
log.SetLevel(level) log.SetLevel(level)
if len(traefikConfiguration.ConfigFile) != 0 {
log.Infof("Using TOML configuration file %s", traefikConfiguration.ConfigFile)
}
if traefikConfiguration.File != nil && len(traefikConfiguration.File.Filename) == 0 {
// no filename, setting to global config file
if len(traefikConfiguration.ConfigFile) != 0 {
traefikConfiguration.File.Filename = traefikConfiguration.ConfigFile
} else {
log.Errorln("Error using file configuration backend, no filename defined")
}
}
if len(traefikConfiguration.EntryPoints) == 0 {
traefikConfiguration.EntryPoints = map[string]*EntryPoint{"http": {Address: ":80"}}
traefikConfiguration.DefaultEntryPoints = []string{"http"}
}
if len(globalConfiguration.TraefikLogsFile) > 0 { if len(globalConfiguration.TraefikLogsFile) > 0 {
fi, err := os.OpenFile(globalConfiguration.TraefikLogsFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) fi, err := os.OpenFile(globalConfiguration.TraefikLogsFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
defer func() { defer func() {