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.