natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.72k stars 580 forks source link

`Write` after `Close` on Logger still works on Windows #200

Open TENX-S opened 6 months ago

TENX-S commented 6 months ago
package main

import (
    "gopkg.in/natefinch/lumberjack.v2"
    "log"
    "time"
)

func main() {
    lj := &lumberjack.Logger{
        Filename:   "test.log",
        MaxSize:    5, // megabytes
        MaxBackups: 3,
    }

    if err := lj.Close(); err != nil {
        panic(err)
    }

    log.SetOutput(lj)
    go func() {
        for {
            log.Println(time.Now().Format(time.RFC3339Nano))
        }
    }()

    time.Sleep(time.Second * 3)
}

I believe there should be no content in test.log, as the file was closed before writing. But it turns out the Close method has no effect on Logger