From 8bcbb5abb4aac0087c8c1d4f37e2b17160604a90 Mon Sep 17 00:00:00 2001 From: Pablo Crivella Date: Thu, 24 Jul 2025 14:58:58 +0200 Subject: [PATCH 1/2] Allow setting slog handler from env var --- cmd/riverui/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/riverui/main.go b/cmd/riverui/main.go index da35b010..a9228e50 100644 --- a/cmd/riverui/main.go +++ b/cmd/riverui/main.go @@ -25,7 +25,7 @@ import ( func main() { ctx := context.Background() - logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + logger := slog.New(getLogHandler(&slog.HandlerOptions{ Level: getLogLevel(), })) @@ -50,6 +50,16 @@ func envBooleanTrue(val string) bool { return val == "1" || val == "true" } +func getLogHandler(opts *slog.HandlerOptions) slog.Handler { + logFormat := strings.ToLower(os.Getenv("RIVER_LOG_FORMAT")) + switch logFormat { + case "json": + return slog.NewJSONHandler(os.Stdout, opts) + default: + return slog.NewTextHandler(os.Stdout, opts) + } +} + func getLogLevel() slog.Level { if envBooleanTrue(os.Getenv("RIVER_DEBUG")) { return slog.LevelDebug From edcded92118d6567275dfac915c1f9fbd8040aa8 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 24 Jul 2025 09:41:31 -0500 Subject: [PATCH 2/2] changelog + readme entries --- CHANGELOG.md | 1 + docs/README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc76b137..a405ef95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a flexible search filter UI for the job list. [PR #344](https://github.com/riverqueue/riverui/pull/344). - Added `riverlog` middleware logs to the job detail UI via a new unified attempts list, rather than separate lists for errors, attempted by, and now logs. [PR #346](https://github.com/riverqueue/riverui/pull/346). - Added a `RIVER_JOB_LIST_HIDE_ARGS_BY_DEFAULT` env and `ServerOpts.JobListHideArgsByDefault` setting to give the backend the ability to choose to hide args from the job list by default. This is useful if your args tend to be encoded or encrypted and not worth looking at in bulk. It can also be overridden in a new settings screen in the UI. [PR #354](https://github.com/riverqueue/riverui/pull/354). +- Added a `RIVER_LOG_FORMAT` env which can be set to `json` to set the `riverui` executable to output JSON instead of `key=value` text. [PR #381](https://github.com/riverqueue/riverui/pull/381). ### Changed diff --git a/docs/README.md b/docs/README.md index 6ef0ee61..0130eac7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,6 +70,8 @@ The `riverui` command utilizes the `RIVER_LOG_LEVEL` environment variable to con * `warn` * `error` +By default logs are written with the [`slog.TextHandler`](https://pkg.go.dev/log/slog#TextHandler) `key=value` format. For JSON output with [`slog.JSONHandler`](https://pkg.go.dev/log/slog#JSONHandler), set `RIVER_LOG_FORMAT=json`. + ## Development See [developing River UI](./development.md).