mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 06:01:48 +02:00
build: switch to slog Handlers
Start using the new slog handlers. With this commit we also remove the need for the LogWriter since we let our LogRotator implement io.Writer and pass that in to our log file handler.
This commit is contained in:
@@ -14,7 +14,8 @@ import (
|
||||
// RotatingLogWriter is a wrapper around the LogWriter that supports log file
|
||||
// rotation.
|
||||
type RotatingLogWriter struct {
|
||||
logWriter *LogWriter
|
||||
// pipe is the write-end pipe for writing to the log rotator.
|
||||
pipe *io.PipeWriter
|
||||
|
||||
rotator *rotator.Rotator
|
||||
}
|
||||
@@ -23,8 +24,8 @@ type RotatingLogWriter struct {
|
||||
//
|
||||
// NOTE: `InitLogRotator` must be called to set up log rotation after creating
|
||||
// the writer.
|
||||
func NewRotatingLogWriter(w *LogWriter) *RotatingLogWriter {
|
||||
return &RotatingLogWriter{logWriter: w}
|
||||
func NewRotatingLogWriter() *RotatingLogWriter {
|
||||
return &RotatingLogWriter{}
|
||||
}
|
||||
|
||||
// InitLogRotator initializes the log file rotator to write logs to logFile and
|
||||
@@ -80,11 +81,20 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string,
|
||||
}
|
||||
}()
|
||||
|
||||
r.logWriter.RotatorPipe = pw
|
||||
r.pipe = pw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write writes the byte slice to the log rotator, if present.
|
||||
func (r *RotatingLogWriter) Write(b []byte) (int, error) {
|
||||
if r.rotator != nil {
|
||||
return r.rotator.Write(b)
|
||||
}
|
||||
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
// Close closes the underlying log rotator if it has already been created.
|
||||
func (r *RotatingLogWriter) Close() error {
|
||||
if r.rotator != nil {
|
||||
|
Reference in New Issue
Block a user