Skip to content

Conversation

@jbergstroem
Copy link
Contributor

@jbergstroem jbergstroem commented Feb 27, 2025

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

We also refactor escapeJsonString to util since it is now a shared function.

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 bugs@bergstroem.nu", but got "Johan Bergström bugs@bergstroem.nu".

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

@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.90%. Comparing base (e179fdd) to head (f2a8155).
⚠️ Report is 18 commits behind head on unstable.

Files with missing lines Patch % Lines
src/server.c 77.77% 2 Missing ⚠️
src/util.c 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1791      +/-   ##
============================================
+ Coverage     73.81%   73.90%   +0.09%     
============================================
  Files           125      125              
  Lines         69347    69353       +6     
============================================
+ Hits          51187    51256      +69     
+ Misses        18160    18097      -63     
Files with missing lines Coverage Δ
src/cli_common.c 62.91% <ø> (+1.09%) ⬆️
src/config.c 78.76% <ø> (ø)
src/server.h 100.00% <ø> (ø)
src/valkey-cli.c 56.78% <ø> (-0.09%) ⬇️
src/util.c 66.66% <92.85%> (+0.49%) ⬆️
src/server.c 88.76% <77.77%> (+0.05%) ⬆️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jbergstroem jbergstroem force-pushed the feat/json-format branch 2 times, most recently from 40b9e16 to c4b19ab Compare February 27, 2025 18:28
@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.

@jbergstroem jbergstroem force-pushed the feat/json-format branch 2 times, most recently from a6938e1 to a67fd89 Compare December 22, 2025 10:35
@jbergstroem
Copy link
Contributor Author

jbergstroem commented Dec 22, 2025

@zuiderkwast long time since last update -- apologies; life came in-between. I've done the changes you requested (refactor, add tests). Will make it ready for review. Finally – if there is places that lacks documentation, feel free to point me to them. Thanks for any feedback!

@jbergstroem jbergstroem marked this pull request as ready for review December 22, 2025 10:36
Introduce a json log format that can be invoked by passing `log-format json` in your config.

Signed-off-by: Johan Bergström <bugs@bergstroem.nu>
Signed-off-by: Johan Bergström <bugs@bergstroem.nu>
Signed-off-by: Johan Bergström <bugs@bergstroem.nu>
Signed-off-by: Johan Bergström <bugs@bergstroem.nu>
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

LGTM

@valkey-io/core-team When we decided to add the logfmt format in #1022 (comment), it appears we also already agreed to add the JSON log format. Please comment if you don't agree.

@zuiderkwast zuiderkwast moved this to In Progress in Valkey 9.1 Dec 30, 2025
@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Dec 30, 2025
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

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

LGTM.

@enjoy-binbin enjoy-binbin changed the title feat: json log format Adding json support for log-format config Dec 31, 2025
@zuiderkwast zuiderkwast merged commit 269f6e7 into valkey-io:unstable Jan 6, 2026
24 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Valkey 9.1 Jan 6, 2026
@zuiderkwast
Copy link
Contributor

Thanks Johan!

@jbergstroem jbergstroem deleted the feat/json-format branch January 7, 2026 09:15
jdheyburn pushed a commit to jdheyburn/valkey that referenced this pull request Jan 8, 2026
Introduce a json log format that can be invoked by passing `log-format
json` in your config.

We also refactor `escapeJsonString` to `util` since it is now a shared
function.

Closes: valkey-io#1006

---------

Signed-off-by: Johan Bergström <bugs@bergstroem.nu>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[NEW] Output logs as JSON

4 participants