Closes micromata/swd#4
Inject logrus log writer to the default logger implementation
This commit is contained in:
parent
76c23dc14b
commit
c07f1c3dba
1 changed files with 14 additions and 4 deletions
|
@ -1,19 +1,29 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/micromata/swd/app"
|
"github.com/micromata/swd/app"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/webdav"
|
"golang.org/x/net/webdav"
|
||||||
|
syslog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFormatter(&log.TextFormatter{})
|
|
||||||
|
|
||||||
config := app.ParseConfig()
|
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{
|
wdHandler := &webdav.Handler{
|
||||||
Prefix: config.Prefix,
|
Prefix: config.Prefix,
|
||||||
FileSystem: &app.Dir{
|
FileSystem: &app.Dir{
|
||||||
|
@ -33,7 +43,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Handle("/", wrapRecovery(app.NewBasicAuthWebdavHandler(a)))
|
http.Handle("/", wrapRecovery(app.NewBasicAuthWebdavHandler(a)))
|
||||||
|
|
||||||
connAddr := fmt.Sprintf("%s:%s", config.Address, config.Port)
|
connAddr := fmt.Sprintf("%s:%s", config.Address, config.Port)
|
||||||
|
|
||||||
if config.TLS != nil {
|
if config.TLS != nil {
|
||||||
|
@ -43,6 +52,7 @@ func main() {
|
||||||
"security": "TLS",
|
"security": "TLS",
|
||||||
}).Info("Server is starting and listening")
|
}).Info("Server is starting and listening")
|
||||||
log.Fatal(http.ListenAndServeTLS(connAddr, config.TLS.CertFile, config.TLS.KeyFile, nil))
|
log.Fatal(http.ListenAndServeTLS(connAddr, config.TLS.CertFile, config.TLS.KeyFile, nil))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"address": config.Address,
|
"address": config.Address,
|
||||||
|
|
Loading…
Reference in a new issue