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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `RIVER_LOG_LEVEL` env for env-based configuration of River UI's log level. Thank you [Taras Turchenko](https://github.com/TArch64)! 🙏🏻 [PR #183](https://github.com/riverqueue/riverui/pull/183).

### Changed

- Allow `HOST` variable to specify specific host variable to bind to. [PR #157](https://github.com/riverqueue/riverui/pull/157).
Expand Down
34 changes: 34 additions & 0 deletions cmd/riverui/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"log/slog"
"os"
"strings"
)

var logger *slog.Logger //nolint:gochecknoglobals

func initLogger() {
options := &slog.HandlerOptions{Level: getLogLevel()}
logger = slog.New(slog.NewTextHandler(os.Stdout, options))
}

func getLogLevel() slog.Level {
debugEnv := os.Getenv("RIVER_DEBUG")
if debugEnv == "1" || debugEnv == "true" {
return slog.LevelDebug
}

env := strings.ToLower(os.Getenv("RIVER_LOG_LEVEL"))

switch env {
case "debug":
return slog.LevelDebug
case "warn":
return slog.LevelWarn
case "error":
return slog.LevelError
default:
return slog.LevelInfo
}
}
10 changes: 1 addition & 9 deletions cmd/riverui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ import (
"riverqueue.com/riverui"
)

var logger *slog.Logger //nolint:gochecknoglobals

func main() {
ctx := context.Background()

if os.Getenv("RIVER_DEBUG") == "1" || os.Getenv("RIVER_DEBUG") == "true" {
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
} else {
logger = slog.New(slog.NewTextHandler(os.Stdout, nil))
}

initLogger()
os.Exit(initAndServe(ctx))
}

Expand Down
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ $ docker run -p 8080:8080 --env DATABASE_URL ghcr.io/riverqueue/riverui:latest

The `riverui` command accepts a `-prefix` arg to set a path prefix on both the API and static assets. When executing the Docker image, this is accepted as a `PATH_PREFIX` env.

### Logging Configuration

The `riverui` command utilizes the `RIVER_LOG_LEVEL` environment variable to configure its logging level. The following values are accepted:

* `debug`
* `info` (default)
* `warn`
* `error`

## Development

See [developing River UI](./development.md).