-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Split global and normal logger tests #15700
Conversation
Move logp global functions to global.go and selective.go, plus split up tests. The change also adds the `nologpglobal` build tag to global.go and global_test.go. By default all global functions are available. When compiling or running a package its test code with `-tags=nologpglobal`, then global logp functions are not available.
assert.Equal(t, "", logs[0].LoggerName) | ||
assert.Equal(t, "critical", logs[0].Message) | ||
} | ||
} |
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.
tests have been moved to global_test.go
@@ -166,47 +93,6 @@ func TestLoggerLevel(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestRecover(t *testing.T) { |
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.
tests have been moved to global_test.go
assert.False(t, HasSelector("publish")) | ||
} | ||
|
||
func TestIsDebug(t *testing.T) { |
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.
tests have been moved to global_test.go
panic(cause) | ||
} | ||
|
||
func TestHasSelector(t *testing.T) { |
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.
test has been moved to selective_test.go
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.
Looks great, happy to see this!
@@ -203,6 +205,14 @@ func (l *Logger) DPanicw(msg string, keysAndValues ...interface{}) { | |||
l.sugar.DPanicw(msg, keysAndValues...) | |||
} | |||
|
|||
// Recover stops a panicking goroutine and logs an Error. | |||
func (l *Logger) Recover(msg string) { |
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.
It doesn't look like this is called anywhere yet (including tests), should it be? Or is it just for use in followups?
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.
It is for the followups.
Move logp global functions to global.go and selective.go, plus split up tests. The change also adds the `nologpglobal` build tag to global.go and global_test.go. By default all global functions are available. When compiling or running a package its test code with `-tags=nologpglobal`, then global logp functions are not available. (cherry picked from commit 4183ba3)
Move logp global functions to global.go and selective.go, plus split up tests. The change also adds the `nologpglobal` build tag to global.go and global_test.go. By default all global functions are available. When compiling or running a package its test code with `-tags=nologpglobal`, then global logp functions are not available. (cherry picked from commit 4183ba3)
What does this PR do?
Move logp global functions to global.go and selective.go, plus split up
tests. The change also adds the
nologpglobal
build tag to global.go and global_test.go.By default all global functions are available. When compiling or
running a package its test code with
-tags=nologpglobal
, then globallogp functions are not available.
Why is it important?
In order to better support structured logging in Beats we want to remove global logging functions. See #15699
This PR adds a build tag that can be used to check for packages that need to be cleaned up. When running
go build -tags=nologpglobal
orgo test -tags=nologpglobal
on a selected package, the compiler will fail until the package and its transitive dependencies have been cleaned up.Checklist
- [ ] I have made corresponding changes to the documentation- [ ] I have made corresponding change to the default configuration files- [ ] I have added tests that prove my fix is effective or that my feature worksAuthor's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs