No color when io.Multiwriter is used
cooperspencer opened this issue · 4 comments
cooperspencer commented
Hi,
I was trying to couple log
with io.Multiwriter and noticed that the colors are gone.
package main
import (
"io"
"os"
"path"
"time"
"github.com/charmbracelet/log"
"gopkg.in/natefinch/lumberjack.v2"
)
func NewRollingFile(dir string) io.Writer {
if dir != "" {
if err := os.MkdirAll(dir, 0o744); err != nil {
log.Error(err, "path", dir)
return nil
}
} else {
dir = "."
}
return &lumberjack.Logger{
Filename: path.Join(dir, "test"),
MaxAge: 7, // days
}
}
func main() {
writers := []io.Writer{}
writers = append(writers, os.Stderr)
writers = append(writers, NewRollingFile("dir"))
writer := io.MultiWriter(writers...)
logger := log.NewWithOptions(writer, log.Options{
ReportCaller: true,
ReportTimestamp: true,
TimeFormat: time.Kitchen,
})
logger.Info("this is a test")
}
cooperspencer commented
#69 will probably solve this
M1ndo commented
Can confirm this issue still persists as no fixes have been proposed yet.
aymanbagabas commented
cooperspencer commented
this solves the issue for me, thanks