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

[logp] Default logging config logs to file #208

Merged
merged 1 commit into from
May 29, 2024

Conversation

belimawr
Copy link
Contributor

What does this PR do?

The default log configuration must log to files. A test is added to ensure the default logging configuration logs to files as well as some other default fields are correctly set.

Why is it important?

It fixes the default behaviour that was broken by #205

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • Test Beats with this change
  • Test Elastic-Agent with this change

## Related issues

@belimawr belimawr added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label May 29, 2024
@belimawr belimawr requested a review from a team as a code owner May 29, 2024 13:45
@belimawr belimawr requested review from AndersonQ and rdner and removed request for a team May 29, 2024 13:45
@belimawr belimawr force-pushed the log-to-file-by-default branch 2 times, most recently from c3cb526 to cc05474 Compare May 29, 2024 14:07
@pierrehilbert pierrehilbert requested review from faec and leehinman and removed request for AndersonQ and rdner May 29, 2024 14:10
@belimawr belimawr force-pushed the log-to-file-by-default branch from cc05474 to f5d2ca3 Compare May 29, 2024 14:11
The default log configuration must log to files. A test is added to
ensure the default logging configuration logs to files as well as some
other default fields are correctly set.
@belimawr belimawr force-pushed the log-to-file-by-default branch from f5d2ca3 to 9a04ff4 Compare May 29, 2024 14:19
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@belimawr belimawr requested a review from cmacknz May 29, 2024 14:39
Comment on lines +53 to +55
_, fileName, lineNum, _ := runtime.Caller(0)
lineNum-- // We want the line number from the log
fileName = filepath.Base(fileName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this here? This is really a test of what the logger.Info calls does isn't it?

The point of this test is to prove that the default configuration logs to files, not to also test exact format of the logs themselves? Is that correct?

I think I am mostly concerned that this test succeeding currently depends on the exact placement of these lines in the file. It seems unnecessary to maintain this to verify what you need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this test is to prove that the default configuration logs to files, not to also test exact format of the logs themselves? Is that correct?

Yes, but as I wrote the test I thought it would be nice to ensure some other fields we expect are there as well. The file and line number are essential exactly which bit of the code is producing the log entry. They're the first thing I look at when I'm dealing with a log entry I'm not used to see.

I don't mind removing this assertion, however I believe we should have a test that ensures our expected default behaviour, which includes some essential fields.

I think I am mostly concerned that this test succeeding currently depends on the exact placement of these lines in the file. It seems unnecessary to maintain this to verify what you need to.

I get that, hence I'm reading them from the runtime instead of just hard-coding them. As long as L52-54 are always together, no matter where in the file the tests will succeed.

I prefer adding a comment clarifying what those lines are doing and stating they must stay together rather than removing this assertion.

However, if you insist, I'm not against removing them for now and later writing a more comprehensive test with our expectations for a default log entry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't hate it, I just wanted to sanity check how necessary this was. The root of my concern is that this could be fragile, and also if this functionality is already tested as a core part of the upstream zap logger it uses underneath.

It's cheap enough to have here, it is not worth going on a separate adventure to perfectly test every aspect of the logger right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants