propagate logging using config options
This commit is contained in:
@@ -208,9 +208,19 @@ type AuthBasicSutureService struct {
|
||||
}
|
||||
|
||||
// NewAuthBasicSutureService creates a new store.AuthBasicSutureService
|
||||
func NewAuthBasic(ctx context.Context) AuthBasicSutureService {
|
||||
func NewAuthBasic(ctx context.Context, o ...Option) AuthBasicSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return AuthBasicSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -188,9 +188,19 @@ type AuthBearerSutureService struct {
|
||||
}
|
||||
|
||||
// NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService
|
||||
func NewAuthBearer(ctx context.Context) AuthBearerSutureService {
|
||||
func NewAuthBearer(ctx context.Context, o ...Option) AuthBearerSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return AuthBearerSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -336,9 +336,19 @@ type FrontendSutureService struct {
|
||||
}
|
||||
|
||||
// NewFrontendSutureService creates a new frontend.FrontendSutureService
|
||||
func NewFrontend(ctx context.Context) FrontendSutureService {
|
||||
func NewFrontend(ctx context.Context, o ...Option) FrontendSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return FrontendSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -265,9 +265,19 @@ type GatewaySutureService struct {
|
||||
}
|
||||
|
||||
// NewGatewaySutureService creates a new gateway.GatewaySutureService
|
||||
func NewGateway(ctx context.Context) GatewaySutureService {
|
||||
func NewGateway(ctx context.Context, o ...Option) GatewaySutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return GatewaySutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -222,9 +222,19 @@ type GroupsProvider struct {
|
||||
}
|
||||
|
||||
// NewGroupsProvider creates a new storage.GroupsProvider
|
||||
func NewGroupsProvider(ctx context.Context) GroupsProvider {
|
||||
func NewGroupsProvider(ctx context.Context, o ...Option) GroupsProvider {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return GroupsProvider{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package command
|
||||
|
||||
// Option defines a single modifier to an Options attribute.
|
||||
type Option func(o *Options)
|
||||
|
||||
type Options struct {
|
||||
// LogPretty toggles pretty logging lines.
|
||||
LogPretty bool
|
||||
|
||||
// LogColor toggles colored output.
|
||||
LogColor bool
|
||||
|
||||
// LogLevel raises / decreases logging levels.
|
||||
LogLevel string
|
||||
}
|
||||
|
||||
// newOptions initializes the available default options.
|
||||
func newOptions(opts ...Option) Options {
|
||||
opt := Options{}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
}
|
||||
|
||||
return opt
|
||||
}
|
||||
|
||||
// WithLogPretty toggles pretty output for a storage logger.
|
||||
func WithLogPretty(v bool) Option {
|
||||
return func(o *Options) {
|
||||
o.LogPretty = v
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogColor toggles colored output for a storage logger.
|
||||
func WithLogColor(v bool) Option {
|
||||
return func(o *Options) {
|
||||
o.LogColor = v
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogLevel toggles colored output for a storage logger.
|
||||
func WithLogLevel(v string) Option {
|
||||
return func(o *Options) {
|
||||
o.LogLevel = v
|
||||
}
|
||||
}
|
||||
@@ -211,9 +211,19 @@ type SharingSutureService struct {
|
||||
}
|
||||
|
||||
// NewSharingSutureService creates a new store.SharingSutureService
|
||||
func NewSharing(ctx context.Context) SharingSutureService {
|
||||
func NewSharing(ctx context.Context, o ...Option) SharingSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return SharingSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -207,9 +207,19 @@ type StorageHomeSutureService struct {
|
||||
}
|
||||
|
||||
// NewStorageHomeSutureService creates a new storage.StorageHomeSutureService
|
||||
func NewStorageHome(ctx context.Context) StorageHomeSutureService {
|
||||
func NewStorageHome(ctx context.Context, o ...Option) StorageHomeSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return StorageHomeSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -228,10 +228,19 @@ type SutureService struct {
|
||||
}
|
||||
|
||||
// NewSutureService creates a new storagemetadata.SutureService
|
||||
func NewStorageMetadata(ctx context.Context) SutureService {
|
||||
func NewStorageMetadata(ctx context.Context, o ...Option) SutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
return SutureService{
|
||||
ctx: sctx,
|
||||
cancel: cancel,
|
||||
|
||||
@@ -185,9 +185,19 @@ type StoragePublicLinkSutureService struct {
|
||||
}
|
||||
|
||||
// NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService
|
||||
func NewStoragePublicLink(ctx context.Context) StoragePublicLinkSutureService {
|
||||
func NewStoragePublicLink(ctx context.Context, o ...Option) StoragePublicLinkSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return StoragePublicLinkSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -207,9 +207,19 @@ type StorageUsersSutureService struct {
|
||||
}
|
||||
|
||||
// NewStorageUsersSutureService creates a new storage.StorageUsersSutureService
|
||||
func NewStorageUsers(ctx context.Context) StorageUsersSutureService {
|
||||
func NewStorageUsers(ctx context.Context, o ...Option) StorageUsersSutureService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return StorageUsersSutureService{
|
||||
ctx: sctx,
|
||||
|
||||
@@ -223,9 +223,19 @@ type UsersProviderService struct {
|
||||
}
|
||||
|
||||
// NewUsersProviderService creates a new storage.UsersProviderService
|
||||
func NewUsersProviderService(ctx context.Context) UsersProviderService {
|
||||
func NewUsersProviderService(ctx context.Context, o ...Option) UsersProviderService {
|
||||
sctx, cancel := context.WithCancel(ctx)
|
||||
cfg := config.New()
|
||||
|
||||
opts := newOptions(o...)
|
||||
|
||||
// merge config and options
|
||||
cfg.Context = sctx
|
||||
|
||||
cfg.Log.Level = opts.LogLevel
|
||||
cfg.Log.Pretty = opts.LogPretty
|
||||
cfg.Log.Color = opts.LogColor
|
||||
|
||||
cfg.Context = sctx
|
||||
return UsersProviderService{
|
||||
ctx: sctx,
|
||||
|
||||
Reference in New Issue
Block a user