From 875ad911db704c8ad76e0c03452a3c7b6a9fc620 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 7 Jul 2022 17:16:28 +0200 Subject: [PATCH] Fixup previous commit to avoid using blank imports --- ocis-pkg/log/gomicro/log.go | 33 ------------------- ocis-pkg/log/log.go | 27 ++++++++++++++- ocis/pkg/runtime/service/service.go | 21 ++++++++++-- .../app-provider/cmd/app-provider/main.go | 1 - .../app-registry/cmd/app-registry/main.go | 1 - services/audit/cmd/audit/main.go | 1 - services/auth-basic/cmd/auth-basic/main.go | 1 - services/auth-bearer/cmd/auth-bearer/main.go | 1 - .../auth-machine/cmd/auth-machine/main.go | 1 - services/frontend/cmd/frontend/main.go | 1 - services/gateway/cmd/gateway/main.go | 1 - .../graph-explorer/cmd/graph-explorer/main.go | 1 - services/graph/cmd/graph/main.go | 1 - services/groups/cmd/groups/main.go | 1 - services/idm/cmd/idm/main.go | 1 - services/idp/cmd/idp/main.go | 1 - services/nats/cmd/nats/main.go | 1 - .../notifications/cmd/notifications/main.go | 1 - services/ocdav/cmd/ocdav/main.go | 1 - services/ocs/cmd/ocs/main.go | 1 - services/proxy/cmd/proxy/main.go | 1 - services/search/cmd/search/main.go | 1 - services/settings/cmd/settings/main.go | 1 - services/sharing/cmd/sharing/main.go | 1 - .../cmd/storage-publiclink/main.go | 1 - .../storage-shares/cmd/storage-shares/main.go | 1 - .../storage-system/cmd/storage-system/main.go | 1 - .../storage-users/cmd/storage-users/main.go | 1 - services/store/cmd/store/main.go | 1 - services/thumbnails/cmd/thumbnails/main.go | 1 - services/users/cmd/user/main.go | 1 - services/web/cmd/web/main.go | 1 - services/webdav/cmd/webdav/main.go | 1 - 33 files changed, 45 insertions(+), 66 deletions(-) delete mode 100644 ocis-pkg/log/gomicro/log.go diff --git a/ocis-pkg/log/gomicro/log.go b/ocis-pkg/log/gomicro/log.go deleted file mode 100644 index 63b3b8a2be0..00000000000 --- a/ocis-pkg/log/gomicro/log.go +++ /dev/null @@ -1,33 +0,0 @@ -package gomicro - -import ( - "os" - - mzlog "github.com/go-micro/plugins/v4/logger/zerolog" - "github.com/rs/zerolog" - "go-micro.dev/v4/logger" -) - -func init() { - // this is ugly, but "logger.DefaultLogger" is a global variable and we need to set it _before_ anybody uses it - setMicroLogger() -} - -// for logging reasons we don't want the same logging level on both oCIS and micro. As a framework builder we do not -// want to expose to the end user the internal framework logs unless explicitly specified. -func setMicroLogger() { - if os.Getenv("MICRO_LOG_LEVEL") == "" { - _ = os.Setenv("MICRO_LOG_LEVEL", "error") - } - - lev, err := zerolog.ParseLevel(os.Getenv("MICRO_LOG_LEVEL")) - if err != nil { - lev = zerolog.ErrorLevel - } - logger.DefaultLogger = mzlog.NewLogger( - logger.WithLevel(logger.Level(lev)), - logger.WithFields(map[string]interface{}{ - "system": "go-micro", - }), - ) -} diff --git a/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index e90fa1dcb30..14a89d5ea85 100644 --- a/ocis-pkg/log/log.go +++ b/ocis-pkg/log/log.go @@ -6,12 +6,37 @@ import ( "strings" "time" + mzlog "github.com/go-micro/plugins/v4/logger/zerolog" "github.com/owncloud/ocis/v2/ocis-pkg/shared" - "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "go-micro.dev/v4/logger" ) +func init() { + // this is ugly, but "logger.DefaultLogger" is a global variable and we need to set it _before_ anybody uses it + setMicroLogger() +} + +// for logging reasons we don't want the same logging level on both oCIS and micro. As a framework builder we do not +// want to expose to the end user the internal framework logs unless explicitly specified. +func setMicroLogger() { + if os.Getenv("MICRO_LOG_LEVEL") == "" { + _ = os.Setenv("MICRO_LOG_LEVEL", "error") + } + + lev, err := zerolog.ParseLevel(os.Getenv("MICRO_LOG_LEVEL")) + if err != nil { + lev = zerolog.ErrorLevel + } + logger.DefaultLogger = mzlog.NewLogger( + logger.WithLevel(logger.Level(lev)), + logger.WithFields(map[string]interface{}{ + "system": "go-micro", + }), + ) +} + // Logger simply wraps the zerolog logger. type Logger struct { zerolog.Logger diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 4c053209baf..dc5e76bfdbd 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -15,6 +15,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + mzlog "github.com/go-micro/plugins/v4/logger/zerolog" "github.com/mohae/deepcopy" "github.com/olekukonko/tablewriter" @@ -49,9 +50,9 @@ import ( users "github.com/owncloud/ocis/v2/services/users/pkg/command" web "github.com/owncloud/ocis/v2/services/web/pkg/command" webdav "github.com/owncloud/ocis/v2/services/webdav/pkg/command" + "github.com/rs/zerolog" "github.com/thejerf/suture/v4" - - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" + "go-micro.dev/v4/logger" ) var ( @@ -156,6 +157,8 @@ func Start(o ...Option) error { halt := make(chan os.Signal, 1) signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + setMicroLogger() + // tolerance controls backoff cycles from the supervisor. tolerance := 5 totalBackoff := 0 @@ -298,3 +301,17 @@ func trap(s *Service, halt chan os.Signal) { s.Log.Debug().Str("service", "runtime service").Msgf("terminating with signal: %v", s) os.Exit(0) } + +// for logging reasons we don't want the same logging level on both oCIS and micro. As a framework builder we do not +// want to expose to the end user the internal framework logs unless explicitly specified. +func setMicroLogger() { + if os.Getenv("MICRO_LOG_LEVEL") == "" { + _ = os.Setenv("MICRO_LOG_LEVEL", "error") + } + + lev, err := zerolog.ParseLevel(os.Getenv("MICRO_LOG_LEVEL")) + if err != nil { + lev = zerolog.ErrorLevel + } + logger.DefaultLogger = mzlog.NewLogger(logger.WithLevel(logger.Level(lev))) +} diff --git a/services/app-provider/cmd/app-provider/main.go b/services/app-provider/cmd/app-provider/main.go index d70739cee02..c4afd562c2d 100644 --- a/services/app-provider/cmd/app-provider/main.go +++ b/services/app-provider/cmd/app-provider/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/app-provider/pkg/command" "github.com/owncloud/ocis/v2/services/app-provider/pkg/config/defaults" ) diff --git a/services/app-registry/cmd/app-registry/main.go b/services/app-registry/cmd/app-registry/main.go index 1c59dde722e..6a9d91f7d68 100644 --- a/services/app-registry/cmd/app-registry/main.go +++ b/services/app-registry/cmd/app-registry/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/app-registry/pkg/command" "github.com/owncloud/ocis/v2/services/app-registry/pkg/config/defaults" ) diff --git a/services/audit/cmd/audit/main.go b/services/audit/cmd/audit/main.go index 18b8ceb25a5..f365e874ec3 100644 --- a/services/audit/cmd/audit/main.go +++ b/services/audit/cmd/audit/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/audit/pkg/command" "github.com/owncloud/ocis/v2/services/audit/pkg/config/defaults" ) diff --git a/services/auth-basic/cmd/auth-basic/main.go b/services/auth-basic/cmd/auth-basic/main.go index 572feb4cf3f..ec5af41edf3 100644 --- a/services/auth-basic/cmd/auth-basic/main.go +++ b/services/auth-basic/cmd/auth-basic/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/auth-basic/pkg/command" "github.com/owncloud/ocis/v2/services/auth-basic/pkg/config/defaults" ) diff --git a/services/auth-bearer/cmd/auth-bearer/main.go b/services/auth-bearer/cmd/auth-bearer/main.go index 808f449861b..8617701cfde 100644 --- a/services/auth-bearer/cmd/auth-bearer/main.go +++ b/services/auth-bearer/cmd/auth-bearer/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/command" "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/config/defaults" ) diff --git a/services/auth-machine/cmd/auth-machine/main.go b/services/auth-machine/cmd/auth-machine/main.go index 8d543a6058c..937b0b20cdf 100644 --- a/services/auth-machine/cmd/auth-machine/main.go +++ b/services/auth-machine/cmd/auth-machine/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/auth-machine/pkg/command" "github.com/owncloud/ocis/v2/services/auth-machine/pkg/config/defaults" ) diff --git a/services/frontend/cmd/frontend/main.go b/services/frontend/cmd/frontend/main.go index 48296d2a3c5..cbdc5dac510 100644 --- a/services/frontend/cmd/frontend/main.go +++ b/services/frontend/cmd/frontend/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/frontend/pkg/command" "github.com/owncloud/ocis/v2/services/frontend/pkg/config/defaults" ) diff --git a/services/gateway/cmd/gateway/main.go b/services/gateway/cmd/gateway/main.go index 2eab06a6d31..d22e804011a 100644 --- a/services/gateway/cmd/gateway/main.go +++ b/services/gateway/cmd/gateway/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/gateway/pkg/command" "github.com/owncloud/ocis/v2/services/gateway/pkg/config/defaults" ) diff --git a/services/graph-explorer/cmd/graph-explorer/main.go b/services/graph-explorer/cmd/graph-explorer/main.go index 34d83280437..092cd87412f 100644 --- a/services/graph-explorer/cmd/graph-explorer/main.go +++ b/services/graph-explorer/cmd/graph-explorer/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/graph-explorer/pkg/command" "github.com/owncloud/ocis/v2/services/graph-explorer/pkg/config/defaults" ) diff --git a/services/graph/cmd/graph/main.go b/services/graph/cmd/graph/main.go index e899d008606..7844daa6af9 100644 --- a/services/graph/cmd/graph/main.go +++ b/services/graph/cmd/graph/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/graph/pkg/command" "github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults" ) diff --git a/services/groups/cmd/groups/main.go b/services/groups/cmd/groups/main.go index 774804a503d..2172fc84505 100644 --- a/services/groups/cmd/groups/main.go +++ b/services/groups/cmd/groups/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/groups/pkg/command" "github.com/owncloud/ocis/v2/services/groups/pkg/config/defaults" ) diff --git a/services/idm/cmd/idm/main.go b/services/idm/cmd/idm/main.go index fbf3d5b5c76..f30202e587d 100644 --- a/services/idm/cmd/idm/main.go +++ b/services/idm/cmd/idm/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/idm/pkg/command" "github.com/owncloud/ocis/v2/services/idm/pkg/config/defaults" ) diff --git a/services/idp/cmd/idp/main.go b/services/idp/cmd/idp/main.go index 864e1da308b..174283c909a 100644 --- a/services/idp/cmd/idp/main.go +++ b/services/idp/cmd/idp/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/idp/pkg/command" "github.com/owncloud/ocis/v2/services/idp/pkg/config/defaults" ) diff --git a/services/nats/cmd/nats/main.go b/services/nats/cmd/nats/main.go index 238cd5f6427..4b5803ac78c 100644 --- a/services/nats/cmd/nats/main.go +++ b/services/nats/cmd/nats/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/nats/pkg/command" "github.com/owncloud/ocis/v2/services/nats/pkg/config/defaults" ) diff --git a/services/notifications/cmd/notifications/main.go b/services/notifications/cmd/notifications/main.go index 0d596381211..5d5752af388 100644 --- a/services/notifications/cmd/notifications/main.go +++ b/services/notifications/cmd/notifications/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/notifications/pkg/command" "github.com/owncloud/ocis/v2/services/notifications/pkg/config/defaults" ) diff --git a/services/ocdav/cmd/ocdav/main.go b/services/ocdav/cmd/ocdav/main.go index 38f93f5a0de..9875027bdb5 100644 --- a/services/ocdav/cmd/ocdav/main.go +++ b/services/ocdav/cmd/ocdav/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/ocdav/pkg/command" "github.com/owncloud/ocis/v2/services/ocdav/pkg/config/defaults" ) diff --git a/services/ocs/cmd/ocs/main.go b/services/ocs/cmd/ocs/main.go index 25151dfc4f7..a2b9021ead9 100644 --- a/services/ocs/cmd/ocs/main.go +++ b/services/ocs/cmd/ocs/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/ocs/pkg/command" "github.com/owncloud/ocis/v2/services/ocs/pkg/config/defaults" ) diff --git a/services/proxy/cmd/proxy/main.go b/services/proxy/cmd/proxy/main.go index a0cf7844811..7db75b5de08 100644 --- a/services/proxy/cmd/proxy/main.go +++ b/services/proxy/cmd/proxy/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/proxy/pkg/command" "github.com/owncloud/ocis/v2/services/proxy/pkg/config/defaults" ) diff --git a/services/search/cmd/search/main.go b/services/search/cmd/search/main.go index 434161fdd52..70103e7bf00 100644 --- a/services/search/cmd/search/main.go +++ b/services/search/cmd/search/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/search/pkg/command" "github.com/owncloud/ocis/v2/services/search/pkg/config/defaults" ) diff --git a/services/settings/cmd/settings/main.go b/services/settings/cmd/settings/main.go index 7fe28a9ebe4..1e21338dd80 100644 --- a/services/settings/cmd/settings/main.go +++ b/services/settings/cmd/settings/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/settings/pkg/command" "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults" ) diff --git a/services/sharing/cmd/sharing/main.go b/services/sharing/cmd/sharing/main.go index 8282d96b70c..54e0996e3fd 100644 --- a/services/sharing/cmd/sharing/main.go +++ b/services/sharing/cmd/sharing/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/sharing/pkg/command" "github.com/owncloud/ocis/v2/services/sharing/pkg/config/defaults" ) diff --git a/services/storage-publiclink/cmd/storage-publiclink/main.go b/services/storage-publiclink/cmd/storage-publiclink/main.go index c15fe2ae92a..6d2415a0070 100644 --- a/services/storage-publiclink/cmd/storage-publiclink/main.go +++ b/services/storage-publiclink/cmd/storage-publiclink/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config/defaults" ) diff --git a/services/storage-shares/cmd/storage-shares/main.go b/services/storage-shares/cmd/storage-shares/main.go index f59275418bd..8a8f9336beb 100644 --- a/services/storage-shares/cmd/storage-shares/main.go +++ b/services/storage-shares/cmd/storage-shares/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command" "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config/defaults" ) diff --git a/services/storage-system/cmd/storage-system/main.go b/services/storage-system/cmd/storage-system/main.go index 34ecd75820c..d9242ea0571 100644 --- a/services/storage-system/cmd/storage-system/main.go +++ b/services/storage-system/cmd/storage-system/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/storage-system/pkg/command" "github.com/owncloud/ocis/v2/services/storage-system/pkg/config/defaults" ) diff --git a/services/storage-users/cmd/storage-users/main.go b/services/storage-users/cmd/storage-users/main.go index 5d0ca3aeb77..c3c7bc7e3f0 100644 --- a/services/storage-users/cmd/storage-users/main.go +++ b/services/storage-users/cmd/storage-users/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/storage-users/pkg/command" "github.com/owncloud/ocis/v2/services/storage-users/pkg/config/defaults" ) diff --git a/services/store/cmd/store/main.go b/services/store/cmd/store/main.go index 7dfbc496a23..ecf42e81938 100644 --- a/services/store/cmd/store/main.go +++ b/services/store/cmd/store/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/store/pkg/command" "github.com/owncloud/ocis/v2/services/store/pkg/config/defaults" ) diff --git a/services/thumbnails/cmd/thumbnails/main.go b/services/thumbnails/cmd/thumbnails/main.go index 86bf69d2bd0..f0a86f58bf2 100644 --- a/services/thumbnails/cmd/thumbnails/main.go +++ b/services/thumbnails/cmd/thumbnails/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/command" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config/defaults" ) diff --git a/services/users/cmd/user/main.go b/services/users/cmd/user/main.go index 2655b24aa10..cae358d3c0b 100644 --- a/services/users/cmd/user/main.go +++ b/services/users/cmd/user/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/users/pkg/command" "github.com/owncloud/ocis/v2/services/users/pkg/config/defaults" ) diff --git a/services/web/cmd/web/main.go b/services/web/cmd/web/main.go index d2403a3a689..9974c37fc9a 100644 --- a/services/web/cmd/web/main.go +++ b/services/web/cmd/web/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/web/pkg/command" "github.com/owncloud/ocis/v2/services/web/pkg/config/defaults" ) diff --git a/services/webdav/cmd/webdav/main.go b/services/webdav/cmd/webdav/main.go index 3c811d4011d..84449ec2e3e 100644 --- a/services/webdav/cmd/webdav/main.go +++ b/services/webdav/cmd/webdav/main.go @@ -3,7 +3,6 @@ package main import ( "os" - _ "github.com/owncloud/ocis/v2/ocis-pkg/log/gomicro" "github.com/owncloud/ocis/v2/services/webdav/pkg/command" "github.com/owncloud/ocis/v2/services/webdav/pkg/config/defaults" )