From 5b2b29043cf87a216fb3a3b2fbd0a7acf3342d92 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 15 Jun 2018 16:08:03 +0200 Subject: [PATCH] Use logrus writer instead of os.Stderr --- acme/acme.go | 7 +++++-- integration/fixtures/acme/acme_http01.toml | 1 + integration/fixtures/acme/acme_http01_web.toml | 1 + integration/fixtures/acme/acme_provided.toml | 1 + integration/fixtures/acme/acme_provided_dynamic.toml | 1 + integration/fixtures/acme/no_challenge_acme.toml | 1 + integration/fixtures/acme/wrong_acme.toml | 1 + integration/fixtures/provideracme/acme.toml | 1 + integration/fixtures/provideracme/acme_insan.toml | 1 + integration/fixtures/provideracme/acme_onhost.toml | 1 + provider/acme/provider.go | 4 ++-- 11 files changed, 16 insertions(+), 4 deletions(-) diff --git a/acme/acme.go b/acme/acme.go index 3804141aa..e31bbbdc3 100644 --- a/acme/acme.go +++ b/acme/acme.go @@ -9,7 +9,6 @@ import ( fmtlog "log" "net" "net/http" - "os" "reflect" "strings" "time" @@ -27,6 +26,7 @@ import ( "github.com/containous/traefik/types" "github.com/containous/traefik/version" "github.com/eapache/channels" + "github.com/sirupsen/logrus" "github.com/xenolf/lego/acme" legolog "github.com/xenolf/lego/log" "github.com/xenolf/lego/providers/dns" @@ -65,16 +65,19 @@ type ACME struct { func (a *ACME) init() error { acme.UserAgent = fmt.Sprintf("containous-traefik/%s", version.Version) + if a.ACMELogging { - legolog.Logger = fmtlog.New(os.Stderr, "legolog: ", fmtlog.LstdFlags) + legolog.Logger = fmtlog.New(log.WriterLevel(logrus.DebugLevel), "legolog: ", 0) } else { legolog.Logger = fmtlog.New(ioutil.Discard, "", 0) } + // no certificates in TLS config, so we add a default one cert, err := generate.DefaultCertificate() if err != nil { return err } + a.defaultCertificate = cert a.jobs = channels.NewInfiniteChannel() diff --git a/integration/fixtures/acme/acme_http01.toml b/integration/fixtures/acme/acme_http01.toml index 017e07e44..d63b3dd3c 100644 --- a/integration/fixtures/acme/acme_http01.toml +++ b/integration/fixtures/acme/acme_http01.toml @@ -14,6 +14,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" +acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/acme/acme_http01_web.toml b/integration/fixtures/acme/acme_http01_web.toml index 95316afaf..58defc529 100644 --- a/integration/fixtures/acme/acme_http01_web.toml +++ b/integration/fixtures/acme/acme_http01_web.toml @@ -13,6 +13,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" +acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/acme/acme_provided.toml b/integration/fixtures/acme/acme_provided.toml index 3e83e0928..bf8825c29 100644 --- a/integration/fixtures/acme/acme_provided.toml +++ b/integration/fixtures/acme/acme_provided.toml @@ -16,6 +16,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" +acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/acme/acme_provided_dynamic.toml b/integration/fixtures/acme/acme_provided_dynamic.toml index 552b840d3..cbfe51caa 100644 --- a/integration/fixtures/acme/acme_provided_dynamic.toml +++ b/integration/fixtures/acme/acme_provided_dynamic.toml @@ -14,6 +14,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" +acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/acme/no_challenge_acme.toml b/integration/fixtures/acme/no_challenge_acme.toml index 2480bdaf8..298d27448 100644 --- a/integration/fixtures/acme/no_challenge_acme.toml +++ b/integration/fixtures/acme/no_challenge_acme.toml @@ -17,6 +17,7 @@ email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" onHostRule = true +acmeLogging = true caServer = "http://{{.BoulderHost}}:4001/directory" # No challenge defined diff --git a/integration/fixtures/acme/wrong_acme.toml b/integration/fixtures/acme/wrong_acme.toml index 4137ca3eb..5cdc59a05 100644 --- a/integration/fixtures/acme/wrong_acme.toml +++ b/integration/fixtures/acme/wrong_acme.toml @@ -16,6 +16,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" +acmeLogging = true onHostRule = true caServer = "http://wrongurl:4001/directory" diff --git a/integration/fixtures/provideracme/acme.toml b/integration/fixtures/provideracme/acme.toml index 012a6386f..722fd4740 100644 --- a/integration/fixtures/provideracme/acme.toml +++ b/integration/fixtures/provideracme/acme.toml @@ -14,6 +14,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" + acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/provideracme/acme_insan.toml b/integration/fixtures/provideracme/acme_insan.toml index 3ddc5b545..7287bc4b8 100644 --- a/integration/fixtures/provideracme/acme_insan.toml +++ b/integration/fixtures/provideracme/acme_insan.toml @@ -14,6 +14,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.json" entryPoint = "https" + acmeLogging = true onDemand = false onHostRule = false caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/integration/fixtures/provideracme/acme_onhost.toml b/integration/fixtures/provideracme/acme_onhost.toml index 26992769d..ac78c74fa 100644 --- a/integration/fixtures/provideracme/acme_onhost.toml +++ b/integration/fixtures/provideracme/acme_onhost.toml @@ -14,6 +14,7 @@ defaultEntryPoints = ["http", "https"] email = "test@traefik.io" storage = "/tmp/acme.jsonl" entryPoint = "https" + acmeLogging = true onDemand = {{.OnDemand}} onHostRule = {{.OnHostRule}} caServer = "http://{{.BoulderHost}}:4001/directory" diff --git a/provider/acme/provider.go b/provider/acme/provider.go index 632017f04..958a77707 100644 --- a/provider/acme/provider.go +++ b/provider/acme/provider.go @@ -8,7 +8,6 @@ import ( fmtlog "log" "net" "net/http" - "os" "reflect" "strings" "sync" @@ -24,6 +23,7 @@ import ( "github.com/containous/traefik/types" "github.com/containous/traefik/version" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/xenolf/lego/acme" legolog "github.com/xenolf/lego/log" "github.com/xenolf/lego/providers/dns" @@ -101,7 +101,7 @@ func (p *Provider) SetConfigListenerChan(configFromListenerChan chan types.Confi func (p *Provider) init() error { acme.UserAgent = fmt.Sprintf("containous-traefik/%s", version.Version) if p.ACMELogging { - legolog.Logger = fmtlog.New(os.Stderr, "legolog: ", fmtlog.LstdFlags) + legolog.Logger = fmtlog.New(log.WriterLevel(logrus.DebugLevel), "legolog: ", 0) } else { legolog.Logger = fmtlog.New(ioutil.Discard, "", 0) }