-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
how can I make a logger with different color for each level #648
Comments
I wrote a logging library that wraps zap. It includes a colorful, multi line, dev friendly formatter which can be used with zap. Import “github.com/gemalto/flume”, and the format will register itself as “term-color”. |
I believe you are looking for https://godoc.org/go.uber.org/zap/internal/color. |
It seems like this is the shortest example: package main
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
logger, _ := config.Build()
logger.Info("aaaaa bbbbb")
} that disappointing as other projects are more compact: package main
import "github.com/labstack/gommon/log"
func main() {
log.EnableColor()
log.Info("aaaaa bbbbb")
} @pedgeio can you comment? |
#307 (comment) also works on windows terminals package main
import (
"github.com/mattn/go-colorable"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
aa := zap.NewDevelopmentEncoderConfig()
aa.EncodeLevel = zapcore.CapitalColorLevelEncoder
bb := zap.New(zapcore.NewCore(
zapcore.NewConsoleEncoder(aa),
zapcore.AddSync(colorable.NewColorableStdout()),
zapcore.DebugLevel,
))
bb.Warn("cc")
} |
Any plans to have this working with Right now its only working with |
Would like to have this for production config as well |
No description provided.
The text was updated successfully, but these errors were encountered: