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: json log format #1791

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

jbergstroem
Copy link
Contributor

@jbergstroem jbergstroem commented Feb 27, 2025

Warning

This is a work in progress. Do not merge.

Took a stab at introducing a log format. Any input for how to test this (couldn't find any tests for logfmt) would be much appreciated. If not, should be ok to land.

Todo

  • Refactor escaping strings
  • Consider unit testing

Introduce a json log format that can be invoked by passing log-format json in your config.

Closes: #1006

@jbergstroem
Copy link
Contributor Author

jbergstroem commented Feb 27, 2025

The DCO action is confusing:

Summary

Commit sha: d8edd52, Author: Johan Bergström, Committer: Johan Bergström; Expected "Johan Bergström [email protected]", but got "Johan Bergström [email protected]".

Edit: Fixed. I think it was complaining about using the wrong representation of ö in my last name.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.94%. Comparing base (79d5047) to head (c4b19ab).
Report is 8 commits behind head on unstable.

Files with missing lines Patch % Lines
src/server.c 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1791      +/-   ##
============================================
- Coverage     71.17%   70.94%   -0.24%     
============================================
  Files           123      123              
  Lines         65641    65650       +9     
============================================
- Hits          46720    46573     -147     
- Misses        18921    19077     +156     
Files with missing lines Coverage Δ
src/config.c 78.39% <ø> (ø)
src/server.h 100.00% <ø> (ø)
src/server.c 87.57% <50.00%> (+<0.01%) ⬆️

... and 16 files with indirect coverage changes

Introduce a json log format that can be invoked by passing `log-format json` in your config.

Signed-off-by: Johan Bergström <[email protected]>
@zuiderkwast
Copy link
Contributor

Nice to see this has been started.

We need to escape the strings. There's some code for that in cli_common.c:

sds escapeJsonString(sds s, const char *p, size_t len);

We could move it to another file like util.c, since it will no longer be only for the CLI.

@jbergstroem
Copy link
Contributor Author

Nice to see this has been started.

We need to escape the strings. There's some code for that in cli_common.c:

sds escapeJsonString(sds s, const char *p, size_t len);

We could move it to another file like util.c, since it will no longer be only for the CLI.

Makes sense. Would be much more comfortable if I could test this as we go. Should we start a unit test for basic functions?

@zuiderkwast
Copy link
Contributor

zuiderkwast commented Feb 28, 2025

Would be much more comfortable if I could test this as we go. Should we start a unit test for basic functions?

Yes, we can do that. Another option is to add an integration test where do something that causes something to be logged and then verify what's logged in the log file.

Grep for verify_log_message to find tests that already do this.

We can use the command DEBUG LOG message to write to the log. The server needs to be started with --enable-debug-command yes but that's enabled in the tests already.

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.

[NEW] Output logs as JSON
2 participants