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

Write after Close on Logger still works on Windows #200

Open
TENX-S opened this issue Dec 20, 2023 · 0 comments
Open

Write after Close on Logger still works on Windows #200

TENX-S opened this issue Dec 20, 2023 · 0 comments

Comments

@TENX-S
Copy link

TENX-S commented Dec 20, 2023

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

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

1 participant