Skip to content

Commit

Permalink
add Log use to adapt for log libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Jun 11, 2023
1 parent 0220252 commit 094ddd9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions log/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type defaultLogger struct {
depth int
}

func (l *defaultLogger) Log(level Level, keyvals ...interface{}) {
l.logf(level, nil, keyvals...)
}

// logf logs a message at a given level in the default logger.
// when the level is fatal, it will exit the program.
func (l *defaultLogger) logf(lv Level, format *string, v ...interface{}) {
Expand Down
29 changes: 29 additions & 0 deletions log/fiberlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,66 @@ import (
"io"
)

// Log calls the default logger's Log method.
//
// When using the extensions in gofiber/contrib, for the parameter `keyvals`,
// the first parameter will be filled with `msg` and the rest of the parameters will be filled into the field as key-value
func Log(level Level, keyvals ...interface{}) {
_ = logger.Log(level, keyvals...) //nolint:errcheck // ignore the error

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / lint

logger.Log(level, keyvals...) (no value) used as value) (typecheck)

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / lint

logger.Log(level, keyvals...) (no value) used as value (typecheck)

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / lint

logger.Log(level, keyvals...) (no value) used as value) (typecheck)

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / lint

logger.Log(level, keyvals...) (no value) used as value) (typecheck)

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Security

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x, macos-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x, macos-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, ubuntu-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x, ubuntu-latest)

logger.Log(level, keyvals...) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, macos-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x, macos-latest)

logger.Log(level, keyvals...) (no value) used as value

Check failure on line 13 in log/fiberlog.go

View workflow job for this annotation

GitHub Actions / Compare

logger.Log(level, keyvals...) (no value) used as value
}

// Fatal calls the default logger's Fatal method and then os.Exit(1).
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Fatal(v ...interface{}) {
logger.Fatal(v...)
}

// Error calls the default logger's Error method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Error(v ...interface{}) {
logger.Error(v...)
}

// Warn calls the default logger's Warn method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Warn(v ...interface{}) {
logger.Warn(v...)
}

// Info calls the default logger's Info method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Info(v ...interface{}) {
logger.Info(v...)
}

// Debug calls the default logger's Debug method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Debug(v ...interface{}) {
logger.Debug(v...)
}

// Trace calls the default logger's Trace method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Trace(v ...interface{}) {
logger.Trace(v...)
}

// Panic calls the default logger's Panic method.
//
// When using the log extensions in gofiber/contrib,
// the first parameter will be filled in with `msg` and the rest of the parameters will be filled in as key-values in the field
func Panic(v ...interface{}) {
logger.Panic(v...)
}
Expand Down
1 change: 1 addition & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type AllLogger interface {
FormatLogger
CtxLogger
ControlLogger
Log(level Level, keyvals ...interface{})
}

// Level defines the priority of a log message.
Expand Down

0 comments on commit 094ddd9

Please sign in to comment.