Skip to content
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

Add log.Logger's Output method to Logger&Entry #390

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func (entry *Entry) Panicln(args ...interface{}) {
}
}

func (entry *Entry) Output(calldepth int, s string) error {
entry.Infoln(s)
return nil
}

// Sprintlnn => Sprint no newline. This is to get the behavior of how
// fmt.Sprintln where spaces are always added between operands, regardless of
// their type. Instead of vendoring the Sprintln implementation to spare a
Expand Down
5 changes: 5 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,8 @@ func (logger *Logger) Panicln(args ...interface{}) {
NewEntry(logger).Panicln(args...)
}
}

func (logger *Logger) Output(calldepth int, s string) error {
NewEntry(logger).Println(s)
return nil
}
9 changes: 9 additions & 0 deletions logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func TestWarn(t *testing.T) {
})
}

func TestOutput(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.Output(2, "test")
}, func(fields Fields) {
assert.Equal(t, fields["msg"], "test")
assert.Equal(t, fields["level"], "info")
})
}

func TestInfolnShouldAddSpacesBetweenStrings(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.Infoln("test", "test")
Expand Down