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

Split global and normal logger tests #15700

Merged
merged 3 commits into from
Jan 24, 2020
Merged

Split global and normal logger tests #15700

merged 3 commits into from
Jan 24, 2020

Conversation

urso
Copy link

@urso urso commented Jan 21, 2020

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 global
logp 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 or go test -tags=nologpglobal on a selected package, the compiler will fail until the package and its transitive dependencies have been cleaned up.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] 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 works

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

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)
}
}
Copy link
Author

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) {
Copy link
Author

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) {
Copy link
Author

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) {
Copy link
Author

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

Copy link
Contributor

@faec faec left a 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) {
Copy link
Contributor

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?

Copy link
Author

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.

@urso urso merged commit 4183ba3 into elastic:master Jan 24, 2020
@urso urso deleted the no-global-log branch January 24, 2020 15:03
@urso urso added the v7.7.0 label Jan 24, 2020
urso pushed a commit to urso/beats that referenced this pull request Jan 28, 2020
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)
urso pushed a commit that referenced this pull request Jan 28, 2020
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)
@andresrc andresrc added the Team:Integrations Label for the Integrations team label Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants