MCPcopy
hub / github.com/natefinch/lumberjack / Write

Method Write

lumberjack.go:135–162  ·  view source on GitHub ↗

Write implements io.Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, renamed to include a timestamp of the current time, and a new log file is created using the original log file name. If the length of the write is greater than MaxSize, an error is returned

(p []byte)

Source from the content-addressed store, hash-verified

133// current time, and a new log file is created using the original log file name.
134// If the length of the write is greater than MaxSize, an error is returned.
135func (l *Logger) Write(p []byte) (n int, err error) {
136 l.mu.Lock()
137 defer l.mu.Unlock()
138
139 writeLen := int64(len(p))
140 if writeLen > l.max() {
141 return 0, fmt.Errorf(
142 "write length %d exceeds maximum file size %d", writeLen, l.max(),
143 )
144 }
145
146 if l.file == nil {
147 if err = l.openExistingOrNew(len(p)); err != nil {
148 return 0, err
149 }
150 }
151
152 if l.size+writeLen > l.max() {
153 if err := l.rotate(); err != nil {
154 return 0, err
155 }
156 }
157
158 n, err = l.file.Write(p)
159 l.size += int64(n)
160
161 return n, err
162}
163
164// Close implements io.Closer, and closes the current logfile.
165func (l *Logger) Close() error {

Callers 15

TestMaintainModeFunction · 0.95
TestMaintainOwnerFunction · 0.95
TestCompressMaintainModeFunction · 0.95
TestNewFileFunction · 0.95
TestOpenExistingFunction · 0.95
TestWriteTooLongFunction · 0.95
TestMakeLogDirFunction · 0.95
TestDefaultFilenameFunction · 0.95
TestAutoRotateFunction · 0.95
TestFirstWriteRotateFunction · 0.95
TestMaxBackupsFunction · 0.95

Calls 3

maxMethod · 0.95
openExistingOrNewMethod · 0.95
rotateMethod · 0.95

Tested by 15

TestMaintainModeFunction · 0.76
TestMaintainOwnerFunction · 0.76
TestCompressMaintainModeFunction · 0.76
TestNewFileFunction · 0.76
TestOpenExistingFunction · 0.76
TestWriteTooLongFunction · 0.76
TestMakeLogDirFunction · 0.76
TestDefaultFilenameFunction · 0.76
TestAutoRotateFunction · 0.76
TestFirstWriteRotateFunction · 0.76
TestMaxBackupsFunction · 0.76