Skip to content
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

Open
overtalk opened this issue Nov 9, 2018 · 5 comments
Open

how can I make a logger with different color for each level #648

overtalk opened this issue Nov 9, 2018 · 5 comments

Comments

@overtalk
Copy link

overtalk commented Nov 9, 2018

No description provided.

@ansel1
Copy link
Contributor

ansel1 commented Nov 9, 2018

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”.

@NathanZook
Copy link

I believe you are looking for https://godoc.org/go.uber.org/zap/internal/color.

@ghost
Copy link

ghost commented May 15, 2019

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?

@phanirithvij
Copy link

#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")
}

@sc-atompower
Copy link

I believe you are looking for https://godoc.org/go.uber.org/zap/internal/color.

Any plans to have this working with zap.NewProductionConfig()

Right now its only working with zap.NewDevelopmentConfig()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants