charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

No colors issue Persists With Io.MultiWriter. #80

Closed M1ndo closed 1 year ago

M1ndo commented 1 year ago

69 Didn't fix the issue not in my case. I can't seem to get colors working unless setting color file to termenv.TrueColor.

Os: Arch Linux

package main

import (
    "github.com/charmbracelet/log"
    "io"
    "os"
    "time"
    // "github.com/muesli/termenv"
)

func main() {
    file := "logger.log"
    LogFile, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
    if err != nil {
        panic(err)
    }
    writers := []io.Writer{}
    writers = append(writers, os.Stderr)
    writers = append(writers, LogFile)
    writer := io.MultiWriter(writers...)
    // OR io.MultiWriter(LogFile, os.Stdout)

    Options := log.Options{
        TimeFunction:    time.Now,
        TimeFormat:      time.DateTime,
        ReportTimestamp: true,
        Level:           log.InfoLevel,
        Prefix:          "Logging 👾 ",
    }

    logger := log.NewWithOptions(writer, Options)
    // logger.SetColorProfile(termenv.TrueColor) // Works
    logger.Info("this is a test")
}
dezren39 commented 1 year ago

84 solved a related issue i had, you may want to give it another swing using latest main branch and you may see that it works nwo.

M1ndo commented 1 year ago

@dezren39 Thanks for the info, it sure did fix it

hayyaun commented 9 months ago

84 solved a related issue i had, you may want to give it another swing using latest main branch and you may see that it works nwo.

How did you manage to fix it? can you give more details please.