lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

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

Open TENX-S opened this issue 6 months ago • 0 comments

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

TENX-S avatar Dec 20 '23 13:12 TENX-S