-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add CronLogAdapter #88 #96
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dddc700
feat: add CronLogAdapter
GGXXLL 4e2984f
Merge branch 'master' into develop
Reasno 7c72f50
fix: otcron.CronLogAdapter key change
GGXXLL d9e0b9a
fix: otcron log error and add test
GGXXLL d6b6d6c
fix: otcron rename to cronopts
GGXXLL 41b010e
feat(otes): allow users to specify extra options (#97)
Reasno 4c30692
feat: add CronLogAdapter
GGXXLL b44b9b8
fix: otcron.CronLogAdapter key change
GGXXLL 6205ed7
fix: otcron log error and add test
GGXXLL 4bb8e6d
fix: otcron rename to cronopts
GGXXLL 3a4cff6
Merge branch 'develop' of github.com:GGXXLL/core into develop
GGXXLL 0952d03
docs: fix gorm doc error
GGXXLL b5eefd4
fix: rename r to c
GGXXLL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cronopts | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
) | ||
|
||
// CronLogAdapter is an adapter between kitlog and cron logger interface | ||
type CronLogAdapter struct { | ||
Logging log.Logger | ||
} | ||
|
||
// Info implements cron.Logger | ||
func (r CronLogAdapter) Info(msg string, keysAndValues ...interface{}) { | ||
_ = level.Info(r.Logging).Log(append([]interface{}{"msg", msg}, keysAndValues...)...) | ||
} | ||
|
||
// Error implements cron.Logger | ||
func (r CronLogAdapter) Error(err error, msg string, keysAndValues ...interface{}) { | ||
_ = level.Error(r.Logging).Log(append([]interface{}{"msg", msg, "err", err}, keysAndValues...)...) | ||
} |
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,23 @@ | ||
package cronopts | ||
|
||
import ( | ||
"bytes" | ||
"github.com/go-kit/kit/log" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestCronLogAdapter_Info(t *testing.T) { | ||
var buf bytes.Buffer | ||
l := CronLogAdapter{Logging: log.NewLogfmtLogger(&buf)} | ||
l.Info("msg", "key","value") | ||
assert.Equal(t, "level=info msg=msg key=value\n", buf.String()) | ||
} | ||
|
||
func TestCronLogAdapter_Error(t *testing.T) { | ||
var buf bytes.Buffer | ||
l := CronLogAdapter{Logging: log.NewLogfmtLogger(&buf)} | ||
l.Error(errors.New("err"),"msg", "key","value") | ||
assert.Equal(t, "level=error msg=msg err=err key=value\n",buf.String()) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般接收器变量的命名是接收器类型的第一个小写字母。