some cleanups to logging code

This commit is contained in:
2026-03-25 22:31:23 -06:00
parent 8fec8cb841
commit 0f0cf5c3f8
+10 -10
View File
@@ -157,30 +157,30 @@ func LogrusPanicLogging(c echo.Context, err error, stack []byte) error {
// amLogFile represents the log output file. // amLogFile represents the log output file.
type amLogFile struct { type amLogFile struct {
mutex sync.Mutex mutex sync.Mutex // mutex for this object
wr io.WriteCloser wr io.WriteCloser // underlying log file
curSize int64 curSize int64 // current size of log file
maxSize int64 maxSize int64 // maximum size of log file
logPath string logPath string // log file path
keep int keep int // number of uncompressed files to keep
keepCompressed int keepCompressed int // number of compressed files to keep
} }
// Write (from io.Writer) writes to the log file. // Write (from io.Writer) writes to the log file.
func (lf *amLogFile) Write(p []byte) (int, error) { func (lf *amLogFile) Write(p []byte) (int, error) {
lf.mutex.Lock() lf.mutex.Lock()
defer lf.mutex.Unlock()
n, err := lf.wr.Write(p) n, err := lf.wr.Write(p)
lf.curSize += int64(n) lf.curSize += int64(n)
lf.mutex.Unlock()
return n, err return n, err
} }
// Close (from io.Closer) closes the log file. // Close (from io.Closer) closes the log file.
func (lf *amLogFile) Close() error { func (lf *amLogFile) Close() error {
lf.mutex.Lock() lf.mutex.Lock()
defer lf.mutex.Unlock()
err := lf.wr.Close() err := lf.wr.Close()
lf.wr = nil lf.wr = nil
lf.mutex.Unlock()
return err return err
} }
@@ -284,13 +284,13 @@ func (lf *amLogFile) rotate() error {
// tryRotate sees if the log file needs to be rotated and does so. // tryRotate sees if the log file needs to be rotated and does so.
func (lf *amLogFile) tryRotate() { func (lf *amLogFile) tryRotate() {
lf.mutex.Lock() lf.mutex.Lock()
defer lf.mutex.Unlock()
if lf.curSize >= lf.maxSize { if lf.curSize >= lf.maxSize {
err := lf.rotate() err := lf.rotate()
if err != nil { if err != nil {
//log.Error("log rotation failed") //log.Error("log rotation failed")
} }
} }
lf.mutex.Unlock()
} }
// open opens the log file and sets up the structure for use. // open opens the log file and sets up the structure for use.