initial support for file logging

This commit is contained in:
A.Unger
2021-03-17 15:26:43 +01:00
parent 732db59bcf
commit 8a3e280d83
16 changed files with 47 additions and 1 deletions

View File

@@ -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,
}

View File

@@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Debug defines the available debug configuration.

View File

@@ -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, ""),

View File

@@ -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,
}

View File

@@ -11,6 +11,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Debug defines the available debug configuration.

View File

@@ -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, ""),

View File

@@ -22,6 +22,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Debug defines the available debug configuration.

View File

@@ -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)
}

View File

@@ -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
}
}

View File

@@ -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),
)
}

View File

@@ -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",

View File

@@ -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

View File

@@ -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,
}

View File

@@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Debug defines the available debug configuration.

View File

@@ -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),
)
}

View File

@@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Debug defines the available debug configuration.