From 711acbb3549fa8a1cdc0b471384f03feccddce19 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sun, 31 Oct 2021 00:08:46 +0200 Subject: [PATCH] inherit logging config from ocis.yaml, let extensions overwrite their logging. Considering using a package level global logging... --- accounts/pkg/command/root.go | 14 +++- glauth/pkg/command/root.go | 14 +++- graph-explorer/pkg/command/root.go | 18 +++-- graph/pkg/command/root.go | 7 +- idp/pkg/command/root.go | 14 +++- ocis-pkg/config/config.go | 84 +++++++++++------------ ocis-pkg/service/debug/service.go | 6 -- ocis-pkg/service/grpc/service.go | 5 -- ocis-pkg/service/http/service.go | 5 -- ocis/pkg/command/ocis_example_config.yaml | 4 ++ ocis/pkg/command/root.go | 54 +++------------ ocs/pkg/command/root.go | 11 +++ proxy/pkg/command/root.go | 2 +- settings/pkg/command/root.go | 14 +++- storage/pkg/command/root.go | 3 +- storage/pkg/command/storagemetadata.go | 2 +- store/pkg/command/root.go | 14 +++- thumbnails/pkg/command/root.go | 11 +++ web/pkg/command/root.go | 11 +++ web/pkg/command/server.go | 2 +- webdav/pkg/command/root.go | 11 +++ 21 files changed, 180 insertions(+), 126 deletions(-) create mode 100644 ocis/pkg/command/ocis_example_config.yaml diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index c4757d23e..6a840af40 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -36,7 +35,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -131,6 +130,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Accounts.Supervised = true } @@ -148,3 +148,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Accounts.Log.File = cfg.Log.File + cfg.Accounts.Log.Color = cfg.Log.Color + cfg.Accounts.Log.Pretty = cfg.Log.Pretty + cfg.Accounts.Log.Level = cfg.Log.Level +} diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index d8b39a980..f5af7df62 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Version = version.String @@ -120,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.GLAuth.Supervised = true } @@ -137,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.GLAuth.Log.File = cfg.Log.File + cfg.GLAuth.Log.Color = cfg.Log.Color + cfg.GLAuth.Log.Pretty = cfg.Log.Pretty + cfg.GLAuth.Log.Level = cfg.Log.Level +} diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 83cdcb186..6b3dd841b 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/graph-explorer/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -91,8 +90,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err := viper.ReadInConfig(); err != nil { switch err.(type) { case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") + //logger.Info(). + // Msg("Continue without config") case viper.UnsupportedConfigError: logger.Fatal(). Err(err). @@ -120,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.GraphExplorer.Supervised = true } @@ -137,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.GraphExplorer.Log.File = cfg.Log.File + cfg.GraphExplorer.Log.Color = cfg.Log.Color + cfg.GraphExplorer.Log.Pretty = cfg.Log.Pretty + cfg.GraphExplorer.Log.Level = cfg.Log.Level +} diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index c342d81b5..cfe7783c9 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -9,7 +9,6 @@ import ( "github.com/thejerf/suture/v4" "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/graph/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" @@ -32,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -92,8 +91,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err := viper.ReadInConfig(); err != nil { switch err.(type) { case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") + //logger.Info(). + // Msg("Continue without config") case viper.UnsupportedConfigError: logger.Fatal(). Err(err). diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 640e75035..cccbc36b2 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -121,6 +120,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.IDP.Supervised = true } @@ -138,3 +138,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.IDP.Log.File = cfg.Log.File + cfg.IDP.Log.Color = cfg.Log.Color + cfg.IDP.Log.Pretty = cfg.Log.Pretty + cfg.IDP.Log.Level = cfg.Log.Level +} diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index b2a88c791..a61bb89a5 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -18,43 +18,43 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string + Addr string `mapstructure:"addr"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"jwt_secret"` } const ( @@ -69,41 +69,41 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string - Host string - Extensions string + Port string `mapstructure:"port"` + Host string `mapstructure:"host"` + Extensions string `mapstructure:"extensions"` } // Config combines all available configuration parts. type Config struct { - // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regards of + // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regard of // what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas // Unsupervised (1) MUST parse config from all known sources. Mode Mode File string - Registry string - Log Log - Debug Debug - HTTP HTTP - GRPC GRPC - Tracing Tracing - TokenManager TokenManager - Runtime Runtime + Registry string `mapstructure:"registry"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + GRPC GRPC `mapstructure:"grpc"` + Tracing Tracing `mapstructure:"tracing"` + TokenManager TokenManager `mapstructure:"token_manager"` + Runtime Runtime `mapstructure:"runtime"` - Accounts *accounts.Config - GLAuth *glauth.Config - Graph *graph.Config - GraphExplorer *graphExplorer.Config - IDP *idp.Config - OCS *ocs.Config - Web *web.Config - Proxy *proxy.Config - Settings *settings.Config - Storage *storage.Config - Store *store.Config - Thumbnails *thumbnails.Config - WebDAV *webdav.Config + Accounts *accounts.Config `mapstructure:"accounts"` + GLAuth *glauth.Config `mapstructure:"glauth"` + Graph *graph.Config `mapstructure:"graph"` + GraphExplorer *graphExplorer.Config `mapstructure:"graph_explorer"` + IDP *idp.Config `mapstructure:"idp"` + OCS *ocs.Config `mapstructure:"ocs"` + Web *web.Config `mapstructure:"web"` + Proxy *proxy.Config `mapstructure:"proxy"` + Settings *settings.Config `mapstructure:"settings"` + Storage *storage.Config `mapstructure:"storage"` + Store *store.Config `mapstructure:"store"` + Thumbnails *thumbnails.Config `mapstructure:"thumbnails"` + WebDAV *webdav.Config `mapstructure:"webdav"` } // New initializes a new configuration with or without defaults. diff --git a/ocis-pkg/service/debug/service.go b/ocis-pkg/service/debug/service.go index a89ea0c53..e0fc93853 100644 --- a/ocis-pkg/service/debug/service.go +++ b/ocis-pkg/service/debug/service.go @@ -15,12 +15,6 @@ import ( // NewService initializes a new debug service. func NewService(opts ...Option) *http.Server { dopts := newOptions(opts...) - - dopts.Logger.Info(). - Str("transport", "debug"). - Str("addr", dopts.Address). - Msg("starting server") - mux := http.NewServeMux() mux.Handle("/metrics", alice.New( diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 34c20c826..c21609b53 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -32,11 +32,6 @@ type Service struct { func NewService(opts ...Option) Service { sopts := newOptions(opts...) - sopts.Logger.Info(). - Str("transport", "grpc"). - Str("addr", sopts.Address). - Msg("starting server") - mopts := []micro.Option{ // first add a server because it will reset any options micro.Server(mgrpcs.NewServer()), diff --git a/ocis-pkg/service/http/service.go b/ocis-pkg/service/http/service.go index f23bf7a88..98317e7a9 100644 --- a/ocis-pkg/service/http/service.go +++ b/ocis-pkg/service/http/service.go @@ -20,11 +20,6 @@ type Service struct { // NewService initializes a new http service. func NewService(opts ...Option) Service { sopts := newOptions(opts...) - sopts.Logger.Info(). - Str("transport", transport(sopts.TLSConfig)). - Str("addr", sopts.Address). - Msg("starting server") - wopts := []micro.Option{ micro.Server(mhttps.NewServer(server.TLSConfig(sopts.TLSConfig))), micro.Address(sopts.Address), diff --git a/ocis/pkg/command/ocis_example_config.yaml b/ocis/pkg/command/ocis_example_config.yaml new file mode 100644 index 000000000..280f0627a --- /dev/null +++ b/ocis/pkg/command/ocis_example_config.yaml @@ -0,0 +1,4 @@ +log: + pretty: true + color: true + level: info diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index e132e2650..43fbafa8b 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -2,18 +2,16 @@ package command import ( "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + gofig "github.com/gookit/config/v2" + gooyaml "github.com/gookit/config/v2/yaml" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/urfave/cli/v2" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/owncloud/ocis/ocis/pkg/flagset" "github.com/owncloud/ocis/ocis/pkg/register" - "github.com/spf13/viper" ) // Execute is the entry point for the ocis command. @@ -25,18 +23,15 @@ func Execute() error { Version: version.String, Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), - Before: func(c *cli.Context) error { return ParseConfig(c, cfg) }, - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - Flags: flagset.RootWithConfig(cfg), } for _, fn := range register.Commands { @@ -70,47 +65,16 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig load configuration for every extension +// ParseConfig loads ocis configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("OCIS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("ocis") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + cnf := gofig.NewWithOptions("ocis", gofig.ParseEnv) + cnf.AddDriver(gooyaml.Driver) + err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/ocis/pkg/command/ocis_example_config.yaml") + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read config") - } - } - - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } + err = cnf.BindStruct("", cfg) return nil } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index d7921b159..281a793ff 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -119,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.OCS.Supervised = true } @@ -136,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.OCS.Log.File = cfg.Log.File + cfg.OCS.Log.Color = cfg.Log.Color + cfg.OCS.Log.Pretty = cfg.Log.Pretty + cfg.OCS.Log.Level = cfg.Log.Level +} diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index eab14795d..54506cac8 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -67,7 +67,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from Viper known paths. +// ParseConfig loads proxy configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { // create a new config and load files and env values onto it since this needs to be thread-safe. cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index de9039845..170b10cd5 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -11,7 +11,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" @@ -32,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -122,6 +121,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Settings.Supervised = true } @@ -139,3 +139,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Settings.Log.File = cfg.Log.File + cfg.Settings.Log.Color = cfg.Log.Color + cfg.Settings.Log.Pretty = cfg.Log.Pretty + cfg.Settings.Log.Level = cfg.Log.Level +} diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 9d0ee792a..a2cce06b1 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/spf13/viper" "github.com/urfave/cli/v2" ) @@ -27,7 +26,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index c27b27a42..74d8b82b4 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -31,7 +31,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command { Name: "storage-metadata", Usage: "Start storage-metadata service", // TODO(refs) at this point it might make sense delegate log flags to each individual storage command. - Flags: append(flagset.StorageMetadata(cfg), flagset.RootWithConfig(cfg)...), + Flags: flagset.StorageMetadata(cfg), Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index a875d5a1b..b16eae65f 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -11,7 +11,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" @@ -32,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -122,6 +121,7 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Store.Supervised = true } @@ -139,3 +139,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Store.Log.File = cfg.Log.File + cfg.Store.Log.Color = cfg.Log.Color + cfg.Store.Log.Pretty = cfg.Log.Pretty + cfg.Store.Log.Level = cfg.Log.Level +} diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 0e297c5ea..c6b0d43a1 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -119,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Thumbnails.Supervised = true } @@ -136,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Thumbnails.Log.File = cfg.Log.File + cfg.Thumbnails.Log.Color = cfg.Log.Color + cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty + cfg.Thumbnails.Log.Level = cfg.Log.Level +} diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index a7b5bbba8..0114791d3 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -111,6 +111,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Web.Supervised = true } @@ -128,3 +129,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Web.Log.File = cfg.Log.File + cfg.Web.Log.Color = cfg.Log.Color + cfg.Web.Log.Pretty = cfg.Log.Pretty + cfg.Web.Log.Level = cfg.Log.Level +} diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 287507628..77ee5dce3 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -22,7 +22,7 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), + Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 99c902e89..bc5bb5fe7 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -117,6 +117,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.WebDAV.Supervised = true } @@ -134,3 +135,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.WebDAV.Log.File = cfg.Log.File + cfg.WebDAV.Log.Color = cfg.Log.Color + cfg.WebDAV.Log.Pretty = cfg.Log.Pretty + cfg.WebDAV.Log.Level = cfg.Log.Level +}