Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复日志打印行数不对的问题 #67

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ polaris/
.vscode/

style_tool/
goimports-reviser
goimports-reviser
*.log
5 changes: 3 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
package grpcpolaris

import (
"fmt"
"log"
"sync/atomic"

"github.com/natefinch/lumberjack"
)

type LogLevel int

Check failure on line 28 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.15)

exported type LogLevel should have comment or be unexported

Check failure on line 28 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.17)

exported type LogLevel should have comment or be unexported

Check failure on line 28 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.16)

exported type LogLevel should have comment or be unexported

Check failure on line 28 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.18)

exported type LogLevel should have comment or be unexported

const (
_ LogLevel = iota
LogDebug

Check failure on line 32 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.15)

exported const LogDebug should have comment (or a comment on this block) or be unexported

Check failure on line 32 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.17)

exported const LogDebug should have comment (or a comment on this block) or be unexported

Check failure on line 32 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.16)

exported const LogDebug should have comment (or a comment on this block) or be unexported

Check failure on line 32 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.18)

exported const LogDebug should have comment (or a comment on this block) or be unexported
LogInfo
LogWarn
LogError
Expand All @@ -36,15 +37,15 @@

var _log Logger = newDefaultLogger()

func SetLogger(logger Logger) {

Check failure on line 40 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.15)

exported function SetLogger should have comment or be unexported

Check failure on line 40 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.17)

exported function SetLogger should have comment or be unexported

Check failure on line 40 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.16)

exported function SetLogger should have comment or be unexported

Check failure on line 40 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.18)

exported function SetLogger should have comment or be unexported
_log = logger
}

func GetLogger() Logger {

Check failure on line 44 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.15)

exported function GetLogger should have comment or be unexported

Check failure on line 44 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.17)

exported function GetLogger should have comment or be unexported

Check failure on line 44 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.16)

exported function GetLogger should have comment or be unexported

Check failure on line 44 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.18)

exported function GetLogger should have comment or be unexported
return _log
}

type Logger interface {

Check failure on line 48 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.15)

exported type Logger should have comment or be unexported

Check failure on line 48 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.17)

exported type Logger should have comment or be unexported

Check failure on line 48 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.16)

exported type Logger should have comment or be unexported

Check failure on line 48 in logger.go

View workflow job for this annotation

GitHub Actions / build (1.18)

exported type Logger should have comment or be unexported
SetLevel(LogLevel)
Debug(format string, args ...interface{})
Info(format string, args ...interface{})
Expand All @@ -70,7 +71,7 @@

levelRef.Store(LogInfo)
return &defaultLogger{
writer: log.New(lumberJackLogger, "", log.Llongfile|log.Ldate|log.Ltime),
writer: log.New(lumberJackLogger, "", log.Lshortfile|log.Ldate|log.Ltime),
levelRef: levelRef,
}
}
Expand Down Expand Up @@ -101,5 +102,5 @@
if curLevel > expectLevel {
return
}
l.writer.Printf(format, args...)
_ = l.writer.Output(3, fmt.Sprintf(format, args...))
}
Loading