Skip to content

Commit

Permalink
ensure error is returned on logging to a closed writer
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Oct 30, 2023
1 parent ac535c9 commit 7cb24ce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions stdlog_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clog
import (
"bytes"
"os"
"path/filepath"
"sync"
"testing"

Expand Down Expand Up @@ -78,3 +79,19 @@ func TestChangeOutput(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "DEBUG message\n", buffer.String())
}

func TestLogOnClosedOutput(t *testing.T) {
logFile := filepath.Join(t.TempDir(), "file.log")
file, err := os.Create(logFile)
require.NoError(t, err)

handler := NewStandardLogHandler(file, "", 0)
err = handler.Close()
assert.NoError(t, err)

err = handler.LogEntry(LogEntry{
Level: LevelDebug,
Values: []interface{}{"message"},
})
assert.Error(t, err)
}

0 comments on commit 7cb24ce

Please sign in to comment.