Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test-race:
# a gate. Analysed for the host and for linux: a file behind a build tag is
# invisible to a run on another platform, which is how a finding in
# watcher_linux.go stayed hidden from every local run and failed in CI.
STATICCHECK ?= honnef.co/go/tools/cmd/staticcheck@v0.7.0
STATICCHECK ?= honnef.co/go/tools/cmd/staticcheck@v0.8.1

# bench runs every benchmark once, briefly. It is a smoke test that the
# benchmarks still compile and run - not a measurement. For numbers worth
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/go-admin-team/go-admin-core/v2

go 1.25.13
go 1.27.1

require (
dario.cat/mergo v1.0.2
Expand Down
35 changes: 23 additions & 12 deletions logger/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,37 @@ func logCallerfilePath(loggingFilePath string) string {
// Log 记录日志条目
// Log logs a log entry
func (l *defaultLogger) Log(level Level, v ...interface{}) {
l.logf(level, "", v...)
if !l.opts.Level.Enabled(level) {
return
}
l.emit(level, fmt.Sprint(v...))
}

// Logf 记录格式化的日志条目
// Logf logs a formatted log entry
func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
l.logf(level, format, v...)
}

// logf 记录日志条目
// logf logs a log entry
func (l *defaultLogger) logf(level Level, format string, v ...interface{}) {
if !l.opts.Level.Enabled(level) {
return
}
l.emit(level, fmt.Sprintf(format, v...))
}

// emit writes one already-rendered message.
//
// The two callers above render the message themselves rather than handing a
// format string and its arguments down here, for two reasons. go vet reads any
// function that forwards both to fmt.Sprintf as a printf wrapper, and then
// reports Log's empty format string as a call "with arguments but no
// formatting directives" - which is precisely what Log is, deliberately, being
// the unformatted entry point. And rendering at the caller keeps that work
// behind the caller's Enabled check, which is where it was before.
//
// emit must stay exactly one frame below Log and Logf. Options.CallerSkipCount
// is counted outwards from the runtime.Caller call below, so adding or removing
// a frame here silently moves every file:line this logger computes.
//
// Callers are responsible for the Enabled check; emit does not repeat it.
func (l *defaultLogger) emit(level Level, message string) {
l.RLock()
fields := copyFields(l.opts.Fields)
l.RUnlock()
Expand All @@ -119,11 +134,7 @@ func (l *defaultLogger) logf(level Level, format string, v ...interface{}) {
rec := dlog.Record{
Timestamp: time.Now(),
Metadata: make(map[string]string, len(fields)),
}
if format == "" {
rec.Message = fmt.Sprint(v...)
} else {
rec.Message = fmt.Sprintf(format, v...)
Message: message,
}

for k, v := range fields {
Expand Down
2 changes: 1 addition & 1 deletion server/listener/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (e *Server) Start(ctx context.Context) error {
<-ctx.Done()
err = e.Shutdown(ctx)
if err != nil {
log.Errorf("%S Server shutdown error: %s", e.name, err.Error())
log.Errorf("%s Server shutdown error: %s", e.name, err.Error())
}
}()
if e.opts.startedHook != nil {
Expand Down
Loading