mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 11:19:39 -06:00
initial support for file logging
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type Log struct {
|
||||
Level string
|
||||
Pretty bool
|
||||
Color bool
|
||||
File string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
|
||||
@@ -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, ""),
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ type Log struct {
|
||||
Level string
|
||||
Pretty bool
|
||||
Color bool
|
||||
File string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
|
||||
@@ -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, ""),
|
||||
|
||||
@@ -22,6 +22,7 @@ type Log struct {
|
||||
Level string
|
||||
Pretty bool
|
||||
Color bool
|
||||
File string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type Log struct {
|
||||
Level string
|
||||
Pretty bool
|
||||
Color bool
|
||||
File string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type Log struct {
|
||||
Level string
|
||||
Pretty bool
|
||||
Color bool
|
||||
File string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
|
||||
Reference in New Issue
Block a user