From ed2c65c1e61e1f534aa2c7fea2b3823ede0bd547 Mon Sep 17 00:00:00 2001 From: dbuduev <3435359+dbuduev@users.noreply.github.com> Date: Wed, 4 Aug 2021 11:26:22 +1200 Subject: [PATCH] feat(logger): Init logrus [DTD-55] (#5232) --- api/cli/cli.go | 2 +- api/cmd/portainer/log.go | 19 +++++++++++++++++++ api/cmd/portainer/main.go | 2 ++ api/go.mod | 1 + api/go.sum | 4 ++-- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 api/cmd/portainer/log.go diff --git a/api/cli/cli.go b/api/cli/cli.go index ca6534893..3a85b7676 100644 --- a/api/cli/cli.go +++ b/api/cli/cli.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/portainer/portainer/api" + portainer "github.com/portainer/portainer/api" "os" "path/filepath" diff --git a/api/cmd/portainer/log.go b/api/cmd/portainer/log.go new file mode 100644 index 000000000..5bab3c5de --- /dev/null +++ b/api/cmd/portainer/log.go @@ -0,0 +1,19 @@ +package main + +import ( + "log" + + "github.com/sirupsen/logrus" +) + +func configureLogger() { + logger := logrus.New() // logger is to implicitly substitute stdlib's log + log.SetOutput(logger.Writer()) + + formatter := &logrus.TextFormatter{DisableTimestamp: true, DisableLevelTruncation: true} + logger.SetFormatter(formatter) + logrus.SetFormatter(formatter) + + logger.SetLevel(logrus.DebugLevel) + logrus.SetLevel(logrus.DebugLevel) +} diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index 7cea5664b..322a58245 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -503,6 +503,8 @@ func buildServer(flags *portainer.CLIFlags) portainer.Server { func main() { flags := initCLI() + configureLogger() + for { server := buildServer(flags) log.Printf("Starting Portainer %s on %s\n", portainer.APIVersion, *flags.Addr) diff --git a/api/go.mod b/api/go.mod index 71d304240..cac0c358e 100644 --- a/api/go.mod +++ b/api/go.mod @@ -31,6 +31,7 @@ require ( github.com/portainer/libcompose v0.5.3 github.com/portainer/libcrypto v0.0.0-20190723020515-23ebe86ab2c2 github.com/portainer/libhttp v0.0.0-20190806161843-ba068f58be33 + github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 diff --git a/api/go.sum b/api/go.sum index 4511f7c23..7428864df 100644 --- a/api/go.sum +++ b/api/go.sum @@ -186,7 +186,6 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c h1:N7A4JCA2G+j5fuFxCsJqjFU/sZe0mj8H0sSoSwbaikw= github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c/go.mod h1:Nn5wlyECw3iJrzi0AhIWg+AJUb4PlRQVW4/3XHH1LZA= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -267,8 +266,9 @@ github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=