Merge pull request #1816 from owncloud/file-logging-ocis-1666

This commit is contained in:
Alex Unger
2021-03-17 22:51:30 +01:00
committed by GitHub
49 changed files with 149 additions and 1 deletions

View File

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

View File

@@ -62,6 +62,7 @@ type Log struct {
Level string
Pretty bool
Color bool
File string
}
// Repo defines which storage implementation is to be used.

View File

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

View File

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

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

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

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{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"},
Destination: &cfg.Log.File,
},
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",

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.Graph.Supervised = true
}
cfg.Graph.Log.File = cfg.Log.File
return SutureService{
cfg: cfg.Graph,
}

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

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

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

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

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

View File

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

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

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

View File

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

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

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

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.Onlyoffice.Supervised = true
}
cfg.Onlyoffice.Log.File = cfg.Log.File
return SutureService{
cfg: cfg.Onlyoffice,
}

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

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

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.Proxy.Supervised = true
}
cfg.Proxy.Log.File = cfg.Log.File
return SutureService{
cfg: cfg.Proxy,
}

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{"PROXY_LOG_FILE", "OCIS_LOG_FILE"},
Destination: &cfg.Log.File,
},
&cli.StringFlag{
Name: "config-file",
Value: "",

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

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

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.

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.Store.Supervised = true
}
cfg.Store.Log.File = cfg.Log.File
return SutureService{
cfg: cfg.Store,
}

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

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

View File

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

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

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

View File

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

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{"WEB_LOG_FILE", "OCIS_LOG_FILE"},
Destination: &cfg.Log.File,
},
&cli.StringFlag{
Name: "config-file",
Value: "",

View File

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

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

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