Skip to content

Commit

Permalink
Remove go1.17 support (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstmdev authored Jun 30, 2023
1 parent ef67c62 commit f1f4643
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
strategy:
matrix:
go: [ '1.17','1.18','1.19','1.20' ]
go: [ '1.18','1.19','1.20' ]
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.3
v0.3.0
14 changes: 7 additions & 7 deletions base_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ type baseLogger struct {
optMu sync.RWMutex // protect Option
}

func (l *baseLogger) Debug(format string, args ...interface{}) {
func (l *baseLogger) Debug(format string, args ...any) {
l.log(level.DebugLevel, format, args...)
}

func (l *baseLogger) Info(format string, args ...interface{}) {
func (l *baseLogger) Info(format string, args ...any) {
l.log(level.InfoLevel, format, args...)
}

func (l *baseLogger) Warn(format string, args ...interface{}) {
func (l *baseLogger) Warn(format string, args ...any) {
l.log(level.WarnLevel, format, args...)
}

func (l *baseLogger) Error(err error, format string, args ...interface{}) {
func (l *baseLogger) Error(err error, format string, args ...any) {
l.logWithErr(err, level.ErrorLevel, format, args...)
}

// Log write a format log
func (l *baseLogger) Log(format string, args ...interface{}) {
func (l *baseLogger) Log(format string, args ...any) {
format = formatter.AppendRowTerminator(format)
if len(args) > 0 {
format = fmt.Sprintf(format, args...)
}
l.Write([]byte(format))
}

func (l *baseLogger) log(lvl level.Level, format string, args ...interface{}) {
func (l *baseLogger) log(lvl level.Level, format string, args ...any) {
l.logWithErr(nil, lvl, format, args...)
}

func (l *baseLogger) logWithErr(err error, lvl level.Level, format string, args ...interface{}) {
func (l *baseLogger) logWithErr(err error, lvl level.Level, format string, args ...any) {
if checkLogLevel(l.lvl, lvl) {
l.optMu.RLock()
c := content.NewContent(lvl, err, l.appendTime, l.timeFormat, format, args...)
Expand Down
16 changes: 8 additions & 8 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (

// Content the log content info
type Content struct {
Level level.Level `json:"level"`
Time *Time `json:"time,omitempty"`
Log string `json:"log"`
Error error `json:"-"`
AppendTime bool `json:"-"`
Args []interface{} `json:"-"`
Level level.Level `json:"level"`
Time *Time `json:"time,omitempty"`
Log string `json:"log"`
Error error `json:"-"`
AppendTime bool `json:"-"`
Args []any `json:"-"`
}

// NewContent return an instance of Content
func NewContent(lvl level.Level, err error, appendTime bool, timeFormat string, log string, args ...interface{}) Content {
func NewContent(lvl level.Level, err error, appendTime bool, timeFormat string, log string, args ...any) Content {
var t *Time
if appendTime {
t = NewTimeWithFormat(time.Now(), timeFormat)
Expand All @@ -26,7 +26,7 @@ func NewContent(lvl level.Level, err error, appendTime bool, timeFormat string,
}

// NewContentWithTime return an instance of Content with specified time
func NewContentWithTime(lvl level.Level, err error, t *Time, log string, args ...interface{}) Content {
func NewContentWithTime(lvl level.Level, err error, t *Time, log string, args ...any) Content {
c := Content{
Level: lvl,
Log: log,
Expand Down
22 changes: 11 additions & 11 deletions default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,63 @@ func InitDefaultLoggerWithSample(logger Logger, sampleRate float64) {
}

// Debug write the debug log
func Debug(format string, args ...interface{}) {
func Debug(format string, args ...any) {
DefaultLogger().Debug(format, args...)
}

// Info write the info log
func Info(format string, args ...interface{}) {
func Info(format string, args ...any) {
DefaultLogger().Info(format, args...)
}

// Warn write the warn log
func Warn(format string, args ...interface{}) {
func Warn(format string, args ...any) {
DefaultLogger().Warn(format, args...)
}

// Error write the error log
func Error(err error, format string, args ...interface{}) {
func Error(err error, format string, args ...any) {
DefaultLogger().Error(err, format, args...)
}

// ErrorIf write the error log if err is not nil
func ErrorIf(err error, format string, args ...interface{}) error {
func ErrorIf(err error, format string, args ...any) error {
if err != nil {
Error(err, format, args...)
}
return err
}

// DebugSample write the debug log by random sampling
func DebugSample(format string, args ...interface{}) {
func DebugSample(format string, args ...any) {
DefaultSampleLogger().Debug(format, args...)
}

// InfoSample write the info log by random sampling
func InfoSample(format string, args ...interface{}) {
func InfoSample(format string, args ...any) {
DefaultSampleLogger().Info(format, args...)
}

// WarnSample write the warn log by random sampling
func WarnSample(format string, args ...interface{}) {
func WarnSample(format string, args ...any) {
DefaultSampleLogger().Warn(format, args...)
}

// ErrorSample write the error log by random sampling
func ErrorSample(err error, format string, args ...interface{}) {
func ErrorSample(err error, format string, args ...any) {
DefaultSampleLogger().Error(err, format, args...)
}

// ErrorIfSample write the error log by random sampling if err is not nil
func ErrorIfSample(err error, format string, args ...interface{}) error {
func ErrorIfSample(err error, format string, args ...any) error {
if err != nil {
ErrorSample(err, format, args...)
}
return err
}

// Log write the log without level
func Log(format string, args ...interface{}) {
func Log(format string, args ...any) {
DefaultLogger().Log(format, args...)
}

Expand Down
10 changes: 5 additions & 5 deletions empty_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ func NewEmptyLogger() Logger {
return logger
}

func (l *emptyLogger) Debug(format string, args ...interface{}) {
func (l *emptyLogger) Debug(format string, args ...any) {

}

func (l *emptyLogger) Info(format string, args ...interface{}) {
func (l *emptyLogger) Info(format string, args ...any) {

}

func (l *emptyLogger) Warn(format string, args ...interface{}) {
func (l *emptyLogger) Warn(format string, args ...any) {

}

func (l *emptyLogger) Error(err error, format string, args ...interface{}) {
func (l *emptyLogger) Error(err error, format string, args ...any) {

}

func (l *emptyLogger) Log(format string, args ...interface{}) {
func (l *emptyLogger) Log(format string, args ...any) {

}

Expand Down
2 changes: 1 addition & 1 deletion file_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (l *fileLogger) write() {
}
}

func (l *fileLogger) innerLog(format string, args ...interface{}) {
func (l *fileLogger) innerLog(format string, args ...any) {
fmt.Printf(format+"\n", args...)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/no-src/log

go 1.17
go 1.18
10 changes: 5 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ type Logger interface {
Writer
Option

Debug(format string, args ...interface{})
Info(format string, args ...interface{})
Warn(format string, args ...interface{})
Error(err error, format string, args ...interface{})
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(err error, format string, args ...any)
}

// Writer implement write to log
type Writer interface {
io.Writer

// Log write log to output
Log(format string, args ...interface{})
Log(format string, args ...any)
// Close to close log and release dependencies
Close() error
}
Expand Down
10 changes: 5 additions & 5 deletions multi_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ func NewMultiLogger(loggers ...Logger) Logger {
return logger
}

func (l *multiLogger) Debug(format string, args ...interface{}) {
func (l *multiLogger) Debug(format string, args ...any) {
for _, logger := range l.loggers {
logger.Debug(format, args...)
}
}

func (l *multiLogger) Info(format string, args ...interface{}) {
func (l *multiLogger) Info(format string, args ...any) {
for _, logger := range l.loggers {
logger.Info(format, args...)
}
}

func (l *multiLogger) Warn(format string, args ...interface{}) {
func (l *multiLogger) Warn(format string, args ...any) {
for _, logger := range l.loggers {
logger.Warn(format, args...)
}
}

func (l *multiLogger) Error(err error, format string, args ...interface{}) {
func (l *multiLogger) Error(err error, format string, args ...any) {
for _, logger := range l.loggers {
logger.Error(err, format, args...)
}
}

func (l *multiLogger) Log(format string, args ...interface{}) {
func (l *multiLogger) Log(format string, args ...any) {
for _, logger := range l.loggers {
logger.Log(format, args...)
}
Expand Down
10 changes: 5 additions & 5 deletions sample_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ func NewSampleLogger(logger Logger, sampleFunc sample.SampleFunc, sampleRate flo
return l
}

func (l *sampleLogger) Debug(format string, args ...interface{}) {
func (l *sampleLogger) Debug(format string, args ...any) {
if l.sample() {
l.logger.Debug(format, args...)
}
}

func (l *sampleLogger) Info(format string, args ...interface{}) {
func (l *sampleLogger) Info(format string, args ...any) {
if l.sample() {
l.logger.Info(format, args...)
}
}

func (l *sampleLogger) Warn(format string, args ...interface{}) {
func (l *sampleLogger) Warn(format string, args ...any) {
if l.sample() {
l.logger.Warn(format, args...)
}
}

func (l *sampleLogger) Error(err error, format string, args ...interface{}) {
func (l *sampleLogger) Error(err error, format string, args ...any) {
if l.sample() {
l.logger.Error(err, format, args...)
}
}

func (l *sampleLogger) Log(format string, args ...interface{}) {
func (l *sampleLogger) Log(format string, args ...any) {
l.logger.Log(format, args...)
}

Expand Down

0 comments on commit f1f4643

Please sign in to comment.