Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion cmd/riverui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}))

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Loading