consolidate log config in nats
Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
||||||
pkgcrypto "github.com/opencloud-eu/opencloud/pkg/crypto"
|
pkgcrypto "github.com/opencloud-eu/opencloud/pkg/crypto"
|
||||||
|
"github.com/opencloud-eu/opencloud/pkg/log"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/runner"
|
"github.com/opencloud-eu/opencloud/pkg/runner"
|
||||||
"github.com/opencloud-eu/opencloud/services/nats/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/nats/pkg/config"
|
||||||
"github.com/opencloud-eu/opencloud/services/nats/pkg/config/parser"
|
"github.com/opencloud-eu/opencloud/services/nats/pkg/config/parser"
|
||||||
@@ -27,7 +28,7 @@ func Server(cfg *config.Config) *cobra.Command {
|
|||||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel)
|
||||||
|
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
if cfg.Context == nil {
|
if cfg.Context == nil {
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
|
|
||||||
// Config combines all available configuration parts.
|
// Config combines all available configuration parts.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service
|
Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service
|
||||||
Service Service `yaml:"-"`
|
Service Service `yaml:"-"`
|
||||||
Log *Log `yaml:"log"`
|
LogLevel string `mapstructure:"level" env:"OC_LOG_LEVEL;NATS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"`
|
||||||
Debug Debug `yaml:"debug"`
|
Debug Debug `yaml:"debug"`
|
||||||
|
|
||||||
Nats Nats `ociConfig:"nats"`
|
Nats Nats `ociConfig:"nats"`
|
||||||
|
|
||||||
|
|||||||
@@ -44,18 +44,9 @@ func DefaultConfig() *config.Config {
|
|||||||
|
|
||||||
// EnsureDefaults adds default values to the configuration if they are not set yet
|
// EnsureDefaults adds default values to the configuration if they are not set yet
|
||||||
func EnsureDefaults(cfg *config.Config) {
|
func EnsureDefaults(cfg *config.Config) {
|
||||||
// provide with defaults for shared logging, since we need a valid destination address for "envdecode".
|
if cfg.LogLevel == "" {
|
||||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
cfg.LogLevel = "error"
|
||||||
cfg.Log = &config.Log{
|
|
||||||
Level: cfg.Commons.Log.Level,
|
|
||||||
Pretty: cfg.Commons.Log.Pretty,
|
|
||||||
Color: cfg.Commons.Log.Color,
|
|
||||||
File: cfg.Commons.Log.File,
|
|
||||||
}
|
|
||||||
} else if cfg.Log == nil {
|
|
||||||
cfg.Log = &config.Log{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanitize sanitizes the configuration
|
// Sanitize sanitizes the configuration
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
// Log defines the available log configuration.
|
|
||||||
type Log struct {
|
|
||||||
Level string `mapstructure:"level" env:"OC_LOG_LEVEL;NATS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"`
|
|
||||||
Pretty bool `mapstructure:"pretty" env:"OC_LOG_PRETTY;NATS_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"`
|
|
||||||
Color bool `mapstructure:"color" env:"OC_LOG_COLOR;NATS_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"`
|
|
||||||
File string `mapstructure:"file" env:"OC_LOG_FILE;NATS_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"`
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package logging
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/log"
|
|
||||||
"github.com/opencloud-eu/opencloud/services/nats/pkg/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Configure initializes a service-specific logger instance.
|
|
||||||
func Configure(name string, cfg *config.Log) log.Logger {
|
|
||||||
return log.NewLogger(
|
|
||||||
log.Name(name),
|
|
||||||
log.Level(cfg.Level),
|
|
||||||
log.Pretty(cfg.Pretty),
|
|
||||||
log.Color(cfg.Color),
|
|
||||||
log.File(cfg.File),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user