-
Notifications
You must be signed in to change notification settings - Fork 66
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
multiwriter file logging #77
Comments
Hi @yusufaine, Log is meant to be used with one writer. Using With this, if io.Writer is not a terminal, colors will be disabled. type MultiLogger struct {
writers []io.Writer
loggers []*log.Logger
}
func NewMultiLogger(wrs ...io.Writer) *MultiLogger {
ml := new(MultiLogger)
ml.writers = make([]io.Writer, len(wrs))
ml.loggers = make([]*log.Logger, len(wrs))
for i, w := range wrs {
ml.writer[i] = w
ml.loggers[i] = log.New(w)
}
return ml
}
func (ml *MultiLogger) Info(msg any, kvs ...any) {
for _, l := range ml.loggers {
l.Info(msg, kvs...)
}
} |
Ah, I see... I've implemented a similar solution as well, thanks for this! |
I'd have a question for this specific approach, how'd you handle a Because if I run a |
@cooperspencer A similar approach can be taken, iterate over the loggers with error severity and https://github.com/charmbracelet/log/blob/main/logger.go#L371 |
I'm glad that #71 fixed the colour issue, but was wondering if there was a way to allow logging to a file without said colour tags.
I currently have a logger setup like this:
but the log file outputs as
The text was updated successfully, but these errors were encountered: