From c07f1c3dba69684e26e7d8535793e70767119235 Mon Sep 17 00:00:00 2001 From: Christian Claus Date: Wed, 25 Apr 2018 14:05:34 +0200 Subject: [PATCH] Closes micromata/swd#4 Inject logrus log writer to the default logger implementation --- cmd/swd/main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/swd/main.go b/cmd/swd/main.go index 0b4021c..5932da1 100644 --- a/cmd/swd/main.go +++ b/cmd/swd/main.go @@ -1,19 +1,29 @@ package main import ( + "errors" "fmt" "github.com/micromata/swd/app" log "github.com/sirupsen/logrus" "golang.org/x/net/webdav" + syslog "log" "net/http" - "errors" ) func main() { - log.SetFormatter(&log.TextFormatter{}) - config := app.ParseConfig() + // Set formatter for logrus + formatter := &log.TextFormatter{} + log.SetFormatter(formatter) + + // Set formatter for default log outputs + logger := log.New() + logger.Formatter = formatter + writer := logger.Writer() + defer writer.Close() + syslog.SetOutput(writer) + wdHandler := &webdav.Handler{ Prefix: config.Prefix, FileSystem: &app.Dir{ @@ -33,7 +43,6 @@ func main() { } http.Handle("/", wrapRecovery(app.NewBasicAuthWebdavHandler(a))) - connAddr := fmt.Sprintf("%s:%s", config.Address, config.Port) if config.TLS != nil { @@ -43,6 +52,7 @@ func main() { "security": "TLS", }).Info("Server is starting and listening") log.Fatal(http.ListenAndServeTLS(connAddr, config.TLS.CertFile, config.TLS.KeyFile, nil)) + } else { log.WithFields(log.Fields{ "address": config.Address,