From 8a3e280d83c5fa917558a9adb3a35312c03080db Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:26:43 +0100 Subject: [PATCH 01/14] initial support for file logging --- glauth/pkg/command/root.go | 2 ++ glauth/pkg/config/config.go | 1 + glauth/pkg/flagset/flagset.go | 6 ++++++ idp/pkg/command/root.go | 2 ++ idp/pkg/config/config.go | 1 + idp/pkg/flagset/flagset.go | 6 ++++++ ocis-pkg/config/config.go | 1 + ocis-pkg/log/log.go | 6 ++++++ ocis-pkg/log/option.go | 8 ++++++++ ocis/pkg/command/root.go | 1 + ocis/pkg/flagset/flagset.go | 6 ++++++ ocis/pkg/runtime/service/service.go | 3 ++- settings/pkg/command/root.go | 2 ++ settings/pkg/config/config.go | 1 + storage/pkg/command/root.go | 1 + storage/pkg/config/config.go | 1 + 16 files changed, 47 insertions(+), 1 deletion(-) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 7db6ee288..55404851d 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -64,6 +64,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -122,6 +123,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.GLAuth.Supervised = true } + cfg.GLAuth.Log.File = cfg.Log.File return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index a83dc84d6..21c101908 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go index c596609cb..ad767a0e7 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -46,6 +46,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"GLAUTH_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "config-file", Value: flags.OverrideDefaultString(cfg.File, ""), diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 3f8c37535..140d03611 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -65,6 +65,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -123,6 +124,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.IDP.Supervised = true } + cfg.IDP.Log.File = cfg.Log.File return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 44f51c415..2fcd3553e 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -11,6 +11,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/idp/pkg/flagset/flagset.go b/idp/pkg/flagset/flagset.go index bf37ba0f7..aea12c4fe 100644 --- a/idp/pkg/flagset/flagset.go +++ b/idp/pkg/flagset/flagset.go @@ -46,6 +46,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"IDP_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "config-file", Value: flags.OverrideDefaultString(cfg.File, ""), diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 973107f7a..4f1b891f0 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -22,6 +22,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index 522023b6c..72e880b1c 100644 --- a/ocis-pkg/log/log.go +++ b/ocis-pkg/log/log.go @@ -61,6 +61,12 @@ func NewLogger(opts ...Option) Logger { }, ), ) + } else if options.File != "" { + f, err := os.OpenFile(options.File, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) + if err != nil { + panic(err) + } + logger = logger.Output(f) } else { logger = zerolog.New(os.Stderr) } diff --git a/ocis-pkg/log/option.go b/ocis-pkg/log/option.go index 023e0da12..756ad16da 100644 --- a/ocis-pkg/log/option.go +++ b/ocis-pkg/log/option.go @@ -9,6 +9,7 @@ type Options struct { Level string Pretty bool Color bool + File string } // newOptions initializes the available default options. @@ -54,3 +55,10 @@ func Color(val bool) Option { o.Color = val } } + +// File provides a function to set the color option. +func File(val string) Option { + return func(o *Options) { + o.File = val + } +} diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index e57b41a34..44f55b9b4 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -74,6 +74,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go index b1f444529..b2be3c854 100644 --- a/ocis/pkg/flagset/flagset.go +++ b/ocis/pkg/flagset/flagset.go @@ -29,6 +29,12 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, + &cli.StringFlag{ + Name: "ocis-log-file", + Usage: "Enable log to file", + EnvVars: []string{"OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 93e8417e1..7eeb49f83 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -19,8 +19,8 @@ import ( "github.com/olekukonko/tablewriter" accounts "github.com/owncloud/ocis/accounts/pkg/command" glauth "github.com/owncloud/ocis/glauth/pkg/command" - graph "github.com/owncloud/ocis/graph/pkg/command" graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/command" + graph "github.com/owncloud/ocis/graph/pkg/command" idp "github.com/owncloud/ocis/idp/pkg/command" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -133,6 +133,7 @@ func Start(o ...Option) error { s.cfg.Storage.Log.Color = s.cfg.Log.Color s.cfg.Storage.Log.Level = s.cfg.Log.Level s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty + s.cfg.Storage.Log.File = s.cfg.Log.File // notify goroutines that they are running on supervised mode s.cfg.Mode = ociscfg.SUPERVISED diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 58e71cf78..e369d832e 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -66,6 +66,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -124,6 +125,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Settings.Supervised = true } + cfg.Settings.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index d699b2d23..f137a9ac4 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 45df05903..eb20e0f8d 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -107,5 +107,6 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 489b005be..11b395e92 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. From 4f3ebb710c52886a0e9aaf1f2dbb029421c1f2f4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:31:51 +0100 Subject: [PATCH 02/14] suport for graph --- graph/pkg/command/root.go | 2 ++ graph/pkg/config/config.go | 1 + graph/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index aae6a9055..ec758502c 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -65,6 +65,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -123,6 +124,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Graph.Supervised = true } + cfg.Graph.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 580652a89..433e9e72f 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index bd9efe93c..c4734797a 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -53,6 +53,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"GRAPH_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", From 1c7b97ab8895ec3aefec5d174502865d54f3279b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:33:21 +0100 Subject: [PATCH 03/14] suport for graph-explorer --- graph-explorer/pkg/command/root.go | 2 ++ graph-explorer/pkg/config/config.go | 1 + graph-explorer/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 8252b158f..d11405507 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -64,6 +64,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -122,6 +123,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.GraphExplorer.Supervised = true } + cfg.GraphExplorer.Log.File = cfg.Log.File return SutureService{ cfg: cfg.GraphExplorer, } diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 9a7c2288e..8bb1cde8e 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/graph-explorer/pkg/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go index 0fc5c27d8..baa5723f2 100644 --- a/graph-explorer/pkg/flagset/flagset.go +++ b/graph-explorer/pkg/flagset/flagset.go @@ -46,6 +46,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", From e15e33d87360c45341bfe67a7d0d3c1f16f4b311 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:35:32 +0100 Subject: [PATCH 04/14] suport for ocs --- ocs/pkg/command/root.go | 2 ++ ocs/pkg/config/config.go | 1 + ocs/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 2bd1945b5..ceb2db3b0 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -63,6 +63,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -121,6 +122,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.OCS.Supervised = true } + cfg.OCS.Log.File = cfg.Log.File return SutureService{ cfg: cfg.OCS, } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 6a4af5d4b..6a01ad55d 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go index a8b1fc7c4..7e428536d 100644 --- a/ocs/pkg/flagset/flagset.go +++ b/ocs/pkg/flagset/flagset.go @@ -22,6 +22,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"OCS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "log-level", Usage: "Set logging level", From bf63bc8c7cb34b083d0e19e5330a1ae65fcb89f2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:36:37 +0100 Subject: [PATCH 05/14] suport for onlyoffice --- onlyoffice/pkg/command/root.go | 2 ++ onlyoffice/pkg/config/config.go | 1 + onlyoffice/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/onlyoffice/pkg/command/root.go b/onlyoffice/pkg/command/root.go index 2ab484ccb..f541c3ca3 100644 --- a/onlyoffice/pkg/command/root.go +++ b/onlyoffice/pkg/command/root.go @@ -64,6 +64,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -122,6 +123,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Onlyoffice.Supervised = true } + cfg.Onlyoffice.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Onlyoffice, } diff --git a/onlyoffice/pkg/config/config.go b/onlyoffice/pkg/config/config.go index bbc6bc6b6..4b8d54822 100644 --- a/onlyoffice/pkg/config/config.go +++ b/onlyoffice/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/onlyoffice/pkg/flagset/flagset.go b/onlyoffice/pkg/flagset/flagset.go index d908dd1b0..d8a59bd5a 100644 --- a/onlyoffice/pkg/flagset/flagset.go +++ b/onlyoffice/pkg/flagset/flagset.go @@ -53,6 +53,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"ONLYOFFICE_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", From 314014ae2131d54de211ab7e4333f96ec4026a4f Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:37:35 +0100 Subject: [PATCH 06/14] suport for store --- store/pkg/command/root.go | 2 ++ store/pkg/config/config.go | 1 + store/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 63a20b4c8..17fc954c0 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -66,6 +66,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -124,6 +125,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Store.Supervised = true } + cfg.Store.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Store, } diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index 3774c6c10..ce9c85252 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/store/pkg/flagset/flagset.go b/store/pkg/flagset/flagset.go index 09f83121b..f87f08efc 100644 --- a/store/pkg/flagset/flagset.go +++ b/store/pkg/flagset/flagset.go @@ -53,6 +53,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"STORE_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", From ed6bdc77b8f0825ef1e77766c0ae11c75ae632ce Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:38:37 +0100 Subject: [PATCH 07/14] suport for thumbnails --- thumbnails/pkg/command/root.go | 2 ++ thumbnails/pkg/config/config.go | 1 + thumbnails/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index ec006eb5f..b1e04ec78 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -63,6 +63,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -121,6 +122,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Thumbnails.Supervised = true } + cfg.Thumbnails.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 9d913633d..d742f9bfe 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go index 85d8b7df1..a7d7152f4 100644 --- a/thumbnails/pkg/flagset/flagset.go +++ b/thumbnails/pkg/flagset/flagset.go @@ -26,6 +26,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "log-level", Usage: "Set logging level", From 9daf14e124f408034acfb66ee888b27c871912e9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:39:24 +0100 Subject: [PATCH 08/14] suport for web --- web/pkg/command/root.go | 2 ++ web/pkg/config/config.go | 1 + web/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 863ee56d4..74348e62d 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -55,6 +55,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -113,6 +114,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Web.Supervised = true } + cfg.Web.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Web, } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 179a8b8ed..4ea408ec2 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/web/pkg/flagset/flagset.go b/web/pkg/flagset/flagset.go index 982377bf5..717663f98 100644 --- a/web/pkg/flagset/flagset.go +++ b/web/pkg/flagset/flagset.go @@ -46,6 +46,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"WEB_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "config-file", Value: "", From 094af97b95b23c09acf8f8d88bfd5196ab0cb56f Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:40:23 +0100 Subject: [PATCH 09/14] suport for webdav --- webdav/pkg/command/root.go | 2 ++ webdav/pkg/config/config.go | 1 + webdav/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index ac52eafda..bbceaba92 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -61,6 +61,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -119,6 +120,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.WebDAV.Supervised = true } + cfg.WebDAV.Log.File = cfg.Log.File return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index f14a96b08..0b0e36462 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/webdav/pkg/flagset/flagset.go b/webdav/pkg/flagset/flagset.go index c0b4847e6..fae18f146 100644 --- a/webdav/pkg/flagset/flagset.go +++ b/webdav/pkg/flagset/flagset.go @@ -22,6 +22,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"WEBDAV_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "log-level", Usage: "Set logging level", From c04abb9f4708eeaff1788b374b82404914653580 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:41:36 +0100 Subject: [PATCH 10/14] suport for accounts --- accounts/pkg/command/root.go | 2 ++ accounts/pkg/config/config.go | 1 + accounts/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 731cf3774..17d17364c 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -75,6 +75,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -133,6 +134,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Accounts.Supervised = true } + cfg.Accounts.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Accounts, } diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 530aefca7..886391942 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -62,6 +62,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Repo defines which storage implementation is to be used. diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index a4a0aaf61..9542d75c3 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -34,6 +34,12 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.BoolFlag{ Name: "tracing-enabled", Usage: "Enable sending traces", From fa27def950629028ac1cf307b15400e79b85c241 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:42:24 +0100 Subject: [PATCH 11/14] suport for proxy --- proxy/pkg/command/root.go | 2 ++ proxy/pkg/config/config.go | 1 + proxy/pkg/flagset/flagset.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index ef72673d0..7f7f5fdd5 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -66,6 +66,7 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } @@ -124,6 +125,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service { if cfg.Mode == 0 { cfg.Proxy.Supervised = true } + cfg.Proxy.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Proxy, } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index e749d5c97..424bcce30 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -7,6 +7,7 @@ type Log struct { Level string Pretty bool Color bool + File string } // Debug defines the available debug configuration. diff --git a/proxy/pkg/flagset/flagset.go b/proxy/pkg/flagset/flagset.go index 8dcb3028a..292676ec8 100644 --- a/proxy/pkg/flagset/flagset.go +++ b/proxy/pkg/flagset/flagset.go @@ -46,6 +46,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { // ServerWithConfig applies cfg to the root flagset func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ + &cli.StringFlag{ + Name: "log-file", + Usage: "Enable log to file", + EnvVars: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, &cli.StringFlag{ Name: "config-file", Value: "", From 9c6e8d7bf392bc0c6eb0851b4811a55dafeccc6e Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 15:59:05 +0100 Subject: [PATCH 12/14] defensive code --- ocis-pkg/log/log.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index 72e880b1c..8b95d0fe4 100644 --- a/ocis-pkg/log/log.go +++ b/ocis-pkg/log/log.go @@ -64,7 +64,8 @@ func NewLogger(opts ...Option) Logger { } else if options.File != "" { f, err := os.OpenFile(options.File, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) if err != nil { - panic(err) + print(fmt.Sprintf("file could not be opened for writing: %s. error: %v", options.File, err)) + os.Exit(1) } logger = logger.Output(f) } else { From 8a64b190a21f8fb95428e12342432513cb616f21 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 16:05:48 +0100 Subject: [PATCH 13/14] fix debug lines --- ocis/pkg/tracing/tracing.go | 1 + settings/pkg/store/filesystem/store.go | 1 + 2 files changed, 2 insertions(+) diff --git a/ocis/pkg/tracing/tracing.go b/ocis/pkg/tracing/tracing.go index 29e8f7b3c..068e25392 100644 --- a/ocis/pkg/tracing/tracing.go +++ b/ocis/pkg/tracing/tracing.go @@ -114,5 +114,6 @@ func NewLogger(cfg *config.Config) log.Logger { log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) } diff --git a/settings/pkg/store/filesystem/store.go b/settings/pkg/store/filesystem/store.go index cf2046b05..8eb3f0341 100644 --- a/settings/pkg/store/filesystem/store.go +++ b/settings/pkg/store/filesystem/store.go @@ -28,6 +28,7 @@ func New(cfg *config.Config) settings.Manager { olog.Color(cfg.Log.Color), olog.Pretty(cfg.Log.Pretty), olog.Level(cfg.Log.Level), + olog.File(cfg.Log.File), ), } From 192fa11d599f3d451c82200464ea5625d226ebe2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Mar 2021 16:57:44 +0100 Subject: [PATCH 14/14] add changelog --- changelog/unreleased/logging-to-file.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changelog/unreleased/logging-to-file.md diff --git a/changelog/unreleased/logging-to-file.md b/changelog/unreleased/logging-to-file.md new file mode 100644 index 000000000..c7d4a38ec --- /dev/null +++ b/changelog/unreleased/logging-to-file.md @@ -0,0 +1,9 @@ +Enhancement: File Logging + +When running supervised, support for configuring all logs to a single log file: +`OCIS_LOG_FILE=/Users/foo/bar/ocis.log MICRO_REGISTRY=etcd bin/ocis server` + +Supports directing log from single extensions to a log file: +`PROXY_LOG_FILE=/Users/foo/bar/proxy.log MICRO_REGISTRY=etcd bin/ocis proxy` + +https://github.com/owncloud/ocis/pull/1816