-
Notifications
You must be signed in to change notification settings - Fork 85
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: [#347] Switch logging channels on runtime #482
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9bb7680
add customization for channel
kkumar-gcc 4791219
chore: update mocks
kkumar-gcc a800507
add testing mocks
kkumar-gcc c8f6cca
Merge remote-tracking branch 'origin/kkumar-gcc/#347' into kkumar-gcc…
kkumar-gcc 588e87e
optimize WithContext
kkumar-gcc ddc452c
add test cases for makeLog
kkumar-gcc fc997ce
optimize test
kkumar-gcc b3c80ac
Merge branch 'master' into kkumar-gcc/#347
kkumar-gcc 568d3e4
add test cases for Channel and Stack methods
kkumar-gcc f5d4139
Merge branch 'master' into kkumar-gcc/#347
kkumar-gcc 3aafec2
allow stack channel in Stack method
kkumar-gcc 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
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,81 @@ | ||
package log | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
mocksconfig "github.com/goravel/framework/mocks/config" | ||
"github.com/goravel/framework/support/color" | ||
) | ||
|
||
func TestNewApplication(t *testing.T) { | ||
app := NewApplication(nil) | ||
assert.NotNil(t, app) | ||
|
||
mockConfig := &mocksconfig.Config{} | ||
mockConfig.On("GetString", "logging.default").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.driver").Return("single") | ||
mockConfig.On("GetString", "logging.channels.test.path").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.level").Return("debug") | ||
mockConfig.On("GetBool", "logging.channels.test.print").Return(true) | ||
app = NewApplication(mockConfig) | ||
assert.NotNil(t, app) | ||
|
||
mockConfig = &mocksconfig.Config{} | ||
mockConfig.On("GetString", "logging.default").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.driver").Return("test") | ||
assert.Contains(t, color.CaptureOutput(func(w io.Writer) { | ||
assert.Nil(t, NewApplication(mockConfig)) | ||
}), "Init facades.Log error: Error logging channel: test") | ||
} | ||
|
||
func TestApplication_Channel(t *testing.T) { | ||
mockConfig := &mocksconfig.Config{} | ||
mockConfig.On("GetString", "logging.default").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.driver").Return("single") | ||
mockConfig.On("GetString", "logging.channels.test.path").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.level").Return("debug") | ||
mockConfig.On("GetBool", "logging.channels.test.print").Return(true) | ||
app := NewApplication(mockConfig) | ||
assert.NotNil(t, app) | ||
assert.NotNil(t, app.Channel("")) | ||
|
||
mockConfig.On("GetString", "logging.channels.dummy.driver").Return("daily") | ||
mockConfig.On("GetString", "logging.channels.dummy.path").Return("dummy") | ||
mockConfig.On("GetString", "logging.channels.dummy.level").Return("debug") | ||
mockConfig.On("GetBool", "logging.channels.dummy.print").Return(true) | ||
mockConfig.On("GetInt", "logging.channels.dummy.days").Return(1) | ||
writer := app.Channel("dummy") | ||
assert.NotNil(t, writer) | ||
|
||
mockConfig.On("GetString", "logging.channels.test2.driver").Return("test2") | ||
assert.Contains(t, color.CaptureOutput(func(w io.Writer) { | ||
assert.Nil(t, app.Channel("test2")) | ||
}), "Init facades.Log error: Error logging channel: test2") | ||
} | ||
|
||
func TestApplication_Stack(t *testing.T) { | ||
mockConfig := &mocksconfig.Config{} | ||
mockConfig.On("GetString", "logging.default").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.driver").Return("single") | ||
mockConfig.On("GetString", "logging.channels.test.path").Return("test") | ||
mockConfig.On("GetString", "logging.channels.test.level").Return("debug") | ||
mockConfig.On("GetBool", "logging.channels.test.print").Return(true) | ||
app := NewApplication(mockConfig) | ||
assert.NotNil(t, app) | ||
assert.NotNil(t, app.Stack([]string{})) | ||
|
||
mockConfig.On("GetString", "logging.channels.test2.driver").Return("test2") | ||
assert.Contains(t, color.CaptureOutput(func(w io.Writer) { | ||
assert.Nil(t, app.Stack([]string{"", "test2", "daily"})) | ||
}), "Init facades.Log error: Error logging channel: test2") | ||
|
||
mockConfig.On("GetString", "logging.channels.dummy.driver").Return("daily") | ||
mockConfig.On("GetString", "logging.channels.dummy.path").Return("dummy") | ||
mockConfig.On("GetString", "logging.channels.dummy.level").Return("debug") | ||
mockConfig.On("GetBool", "logging.channels.dummy.print").Return(true) | ||
mockConfig.On("GetInt", "logging.channels.dummy.days").Return(1) | ||
assert.NotNil(t, app.Stack([]string{"dummy"})) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
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.
Great