mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Add options for customizing threadiness, logger encoding, and global logger level
This commit is contained in:
+19
-1
@@ -1,6 +1,7 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -8,6 +9,17 @@ import (
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var (
|
||||
replaceGlobals bool
|
||||
encoding string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&replaceGlobals, "zap-replace-globals", false, "Whether to change level of global zap logger.")
|
||||
flag.StringVar(&encoding, "zap-encoding", "json", "Zap logger encoding.")
|
||||
|
||||
}
|
||||
|
||||
// NewLogger returns a zap sugared logger configured with json format and caller id
|
||||
func NewLogger(logLevel string) (*zap.SugaredLogger, error) {
|
||||
level := zap.NewAtomicLevelAt(zapcore.InfoLevel)
|
||||
@@ -47,7 +59,7 @@ func NewLogger(logLevel string) (*zap.SugaredLogger, error) {
|
||||
Initial: 100,
|
||||
Thereafter: 100,
|
||||
},
|
||||
Encoding: "json",
|
||||
Encoding: encoding,
|
||||
EncoderConfig: zapEncoderConfig,
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
@@ -60,6 +72,12 @@ func NewLogger(logLevel string) (*zap.SugaredLogger, error) {
|
||||
return logger.Sugar(), nil
|
||||
}
|
||||
|
||||
func ReplaceGlobalIf(logger *zap.Logger) {
|
||||
if replaceGlobals {
|
||||
zap.ReplaceGlobals(logger)
|
||||
}
|
||||
}
|
||||
|
||||
// Console writes to stdout if the console env var exists
|
||||
func Console(a ...interface{}) (n int, err error) {
|
||||
if os.Getenv("console") != "" {
|
||||
|
||||
Reference in New Issue
Block a user