-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b689a51
commit 3fc9116
Showing
11 changed files
with
145 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ jobs: | |
matrix: | ||
go-version: | ||
- "1.21" | ||
- "1.20" | ||
name: lint and test | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/go-co-op/gocron/v2 | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/google/uuid v1.4.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package gocron | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
// Logger is the interface that wraps the basic logging methods | ||
// used by gocron. The methods are modeled after the standard | ||
// library slog package. The default logger is a no-op logger. | ||
// To enable logging, use one of the provided New*Logger functions | ||
// or implement your own Logger. The actual level of Log that is logged | ||
// is handled by the implementation. | ||
type Logger interface { | ||
Debug(msg string, args ...any) | ||
Error(msg string, args ...any) | ||
Info(msg string, args ...any) | ||
Warn(msg string, args ...any) | ||
} | ||
|
||
var _ Logger = (*noOpLogger)(nil) | ||
|
||
type noOpLogger struct{} | ||
|
||
func (_ noOpLogger) Debug(_ string, _ ...any) {} | ||
func (_ noOpLogger) Error(_ string, _ ...any) {} | ||
func (_ noOpLogger) Info(_ string, _ ...any) {} | ||
func (_ noOpLogger) Warn(_ string, _ ...any) {} | ||
|
||
var _ Logger = (*slogLogger)(nil) | ||
|
||
type slogLogger struct { | ||
sl *slog.Logger | ||
} | ||
|
||
func NewJsonSlogLogger(level slog.Level) Logger { | ||
return NewSlogLogger( | ||
slog.New( | ||
slog.NewJSONHandler( | ||
os.Stdout, | ||
&slog.HandlerOptions{ | ||
Level: level, | ||
}, | ||
), | ||
), | ||
) | ||
} | ||
|
||
func NewSlogLogger(sl *slog.Logger) Logger { | ||
return &slogLogger{sl: sl} | ||
} | ||
|
||
func (l *slogLogger) Debug(msg string, args ...any) { | ||
l.sl.Debug(msg, args...) | ||
} | ||
|
||
func (l *slogLogger) Error(msg string, args ...any) { | ||
l.sl.Error(msg, args...) | ||
} | ||
|
||
func (l *slogLogger) Info(msg string, args ...any) { | ||
l.sl.Info(msg, args...) | ||
} | ||
|
||
func (l *slogLogger) Warn(msg string, args ...any) { | ||
l.sl.Warn(msg, args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.