Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support logging to file #1816

Merged
merged 15 commits into from
Mar 17, 2021
2 changes: 2 additions & 0 deletions accounts/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions accounts/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Repo defines which storage implementation is to be used.
Expand Down
6 changes: 6 additions & 0 deletions accounts/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions changelog/unreleased/logging-to-file.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions glauth/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions glauth/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions glauth/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""),
Expand Down
2 changes: 2 additions & 0 deletions graph-explorer/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions graph-explorer/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions graph-explorer/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions graph/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions graph/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions graph/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions idp/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions idp/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions idp/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""),
Expand Down
1 change: 1 addition & 0 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
7 changes: 7 additions & 0 deletions ocis-pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ 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 {
print(fmt.Sprintf("file could not be opened for writing: %s. error: %v", options.File, err))
os.Exit(1)
}
logger = logger.Output(f)
} else {
logger = zerolog.New(os.Stderr)
}
Expand Down
8 changes: 8 additions & 0 deletions ocis-pkg/log/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Options struct {
Level string
Pretty bool
Color bool
File string
}

// newOptions initializes the available default options.
Expand Down Expand Up @@ -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
}
}
1 change: 1 addition & 0 deletions ocis/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down
6 changes: 6 additions & 0 deletions ocis/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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",
Expand Down
3 changes: 2 additions & 1 deletion ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ocis/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
2 changes: 2 additions & 0 deletions ocs/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions ocs/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions ocs/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions onlyoffice/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions onlyoffice/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions onlyoffice/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions proxy/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions proxy/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}

// Debug defines the available debug configuration.
Expand Down
6 changes: 6 additions & 0 deletions proxy/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
Loading