fix(access_logger): nil panic when stdout only, improve concurrency safety

This commit is contained in:
yusing
2025-11-01 01:17:55 +08:00
parent 77e486f4fe
commit e670acb4b8
11 changed files with 207 additions and 117 deletions

View File

@@ -7,26 +7,27 @@ import (
"github.com/spf13/afero"
)
type noLock struct{}
func (noLock) Lock() {}
func (noLock) Unlock() {}
type MockFile struct {
afero.File
noLock
buffered bool
}
var _ SupportRotate = (*MockFile)(nil)
func NewMockFile() *MockFile {
func NewMockFile(buffered bool) *MockFile {
f, _ := afero.TempFile(afero.NewMemMapFs(), "", "")
f.Seek(0, io.SeekEnd)
return &MockFile{
File: f,
File: f,
buffered: buffered,
}
}
func (m *MockFile) ShouldBeBuffered() bool {
return m.buffered
}
func (m *MockFile) Len() int64 {
filesize, _ := m.Seek(0, io.SeekEnd)
_, _ = m.Seek(0, io.SeekStart)
@@ -60,3 +61,7 @@ func (m *MockFile) MustSize() int64 {
size, _ := m.Size()
return size
}
func (m *MockFile) Close() error {
return nil
}