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

No color when io.Multiwriter is used #71

Closed
cooperspencer opened this issue Aug 30, 2023 · 4 comments
Closed

No color when io.Multiwriter is used #71

cooperspencer opened this issue Aug 30, 2023 · 4 comments

Comments

@cooperspencer
Copy link

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
Copy link
Author

#69 will probably solve this

@M1ndo
Copy link

M1ndo commented Sep 27, 2023

Can confirm this issue still persists as no fixes have been proposed yet.

@aymanbagabas
Copy link
Member

#69 is now part of v0.2.5

@cooperspencer
Copy link
Author

this solves the issue for me, thanks

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

No branches or pull requests

3 participants