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

feat: entryhuman: Log the caller's relative module path and function #138

Merged
merged 4 commits into from
Jan 26, 2022

Conversation

nhooyr
Copy link
Contributor

@nhooyr nhooyr commented Jan 25, 2022

At @terrastruct our codebase is currently structured in layers of similar package names and files.

So just printing the base file name for a log's location is vague.

This PR makes sloghuman print the module path to the file and even make it relative to the main module path
if possible. It also makes slog prints the originating function name.

See the test changes for how it looks for when the package is outside the main module.

Unfortunately go test currently doesn't set the binaries build info correctly yet (golang/go#33976) so module paths in test logs will always be absolute. But this is how a relative path looks for cdr.dev/slog:

<cdr.dev/slog/sloggers/sloghuman_test/sloghuman_test.go:21>       TestMake

->

<./sloggers/sloghuman_test/sloghuman_test.go:21>       TestMake

cc @alixander

Some tools like modd (https://github.com/cortesi/modd) will try to color
noncolored text but we don't want them to and so we reset at the
beginning of each line to make sure they aren't playing with our output.
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Wonderful change. Great for readability!

Thank you @nhooyr 👀🥔

@kylecarbs
Copy link
Member

@nhooyr we use semantic to enforce standardized commit messages. Please update the title, and I'll merge!

@nhooyr nhooyr changed the title entryhuman: Log the caller's relative module path and function feat: entryhuman: Log the caller's relative module path and function Jan 25, 2022
@nhooyr
Copy link
Contributor Author

nhooyr commented Jan 25, 2022

@kylecarbs done!

@kylecarbs kylecarbs merged commit b94a5ff into coder:main Jan 26, 2022
@nhooyr nhooyr deleted the terrastruct branch January 26, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants