diff --git a/os/glog/glog_logger.go b/os/glog/glog_logger.go index cd1602784..5eb8b3c24 100644 --- a/os/glog/glog_logger.go +++ b/os/glog/glog_logger.go @@ -290,7 +290,7 @@ func (l *Logger) printToFile(ctx context.Context, t time.Time, in *HandlerInput) // Rotation file size checks. if l.config.RotateSize > 0 && gfile.Size(logFilePath) > l.config.RotateSize { if runtime.GOOS == "windows" { - file := l.getFilePointer(ctx, logFilePath) + file := l.createFpInPool(ctx, logFilePath) if file == nil { intlog.Errorf(ctx, `got nil file pointer for: %s`, logFilePath) return buffer @@ -311,7 +311,7 @@ func (l *Logger) printToFile(ctx context.Context, t time.Time, in *HandlerInput) l.rotateFileBySize(ctx, t) } // Logging content outputting to disk file. - if file := l.getFilePointer(ctx, logFilePath); file == nil { + if file := l.createFpInPool(ctx, logFilePath); file == nil { intlog.Errorf(ctx, `got nil file pointer for: %s`, logFilePath) } else { if _, err := file.Write(buffer.Bytes()); err != nil { @@ -324,8 +324,8 @@ func (l *Logger) printToFile(ctx context.Context, t time.Time, in *HandlerInput) return buffer } -// getFilePointer retrieves and returns a file pointer from file pool. -func (l *Logger) getFilePointer(ctx context.Context, path string) *gfpool.File { +// createFpInPool retrieves and returns a file pointer from file pool. +func (l *Logger) createFpInPool(ctx context.Context, path string) *gfpool.File { file, err := gfpool.Open( path, defaultFileFlags, @@ -339,8 +339,8 @@ func (l *Logger) getFilePointer(ctx context.Context, path string) *gfpool.File { return file } -// getOpenedFilePointer retrieves and returns a file pointer from file pool. -func (l *Logger) getOpenedFilePointer(ctx context.Context, path string) *gfpool.File { +// getFpFromPool retrieves and returns a file pointer from file pool. +func (l *Logger) getFpFromPool(ctx context.Context, path string) *gfpool.File { file := gfpool.Get( path, defaultFileFlags, diff --git a/os/glog/glog_logger_rotate.go b/os/glog/glog_logger_rotate.go index 6090e517a..61192df5b 100644 --- a/os/glog/glog_logger_rotate.go +++ b/os/glog/glog_logger_rotate.go @@ -9,7 +9,6 @@ package glog import ( "context" "fmt" - "runtime" "strings" "time" @@ -170,23 +169,13 @@ func (l *Logger) rotateChecksTimely(ctx context.Context) { return } defer gmlock.Unlock(memoryLockFileKey) - if runtime.GOOS == "windows" { - fp := l.getOpenedFilePointer(ctx, file) - if fp == nil { - intlog.Errorf(ctx, `got nil file pointer for: %s`, file) - return - } - if err := fp.Close(true); err != nil { - intlog.Errorf(ctx, `%+v`, err) - } - } expireRotated = true intlog.Printf( ctx, `%v - %v = %v > %v, rotation expire logging file: %s`, now, mtime, subDuration, l.config.RotateExpire, file, ) - if err := l.doRotateFile(ctx, file); err != nil { + if err = l.doRotateFile(ctx, file); err != nil { intlog.Errorf(ctx, `%+v`, err) } }()