Skip to content

Commit 28739da

Browse files
committed
docs: document settings overrides and env precedence
Add "Programmatic configuration" section to README covering: - Table mapping each env var to its programmatic Option equivalent - WithoutEnvSettings for ignoring all env vars - Precedence order: programmatic options > env vars > defaults - Note that WithLogger disables log level/format options - Usage examples for overrides, WithoutEnvSettings, and WithLogger
1 parent 931367d commit 28739da

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,51 @@ It provides the following information:
9999
| `F1_LOG_LEVEL` | string | `"info"`| Specify the log level of the default logger, one of: `debug`, `warn`, `error` |
100100
| `F1_LOG_FORMAT` | string | `""`| Specify the log format of the default logger, defaults to `text` formatter, allows `json` |
101101

102+
### Programmatic configuration
103+
104+
Every environment variable above has a programmatic equivalent that can be passed as an option to `f1.New()`:
105+
106+
| Environment variable | Programmatic option | Accepted values |
107+
| --- | --- | --- |
108+
| `PROMETHEUS_PUSH_GATEWAY` | `f1.WithPrometheusPushGateway(url)` | `host:port` or full URL |
109+
| `PROMETHEUS_NAMESPACE` | `f1.WithPrometheusNamespace(ns)` | any string |
110+
| `PROMETHEUS_LABEL_ID` | `f1.WithPrometheusLabelID(id)` | any string |
111+
| `LOG_FILE_PATH` | `f1.WithLogFilePath(path)` | file path |
112+
| `F1_LOG_LEVEL` | `f1.WithLogLevel(level)` | `debug`, `info`, `warn`, `error` (case-insensitive) |
113+
| `F1_LOG_FORMAT` | `f1.WithLogFormat(format)` | `text`, `json` (case-insensitive) |
114+
115+
Additionally, `f1.WithoutEnvSettings()` can be used to ignore all environment variables and start from default values.
116+
117+
#### Precedence
118+
119+
Settings are resolved in this order (highest priority first):
120+
121+
1. **Programmatic options** — values passed to `f1.New()`
122+
2. **Environment variables** — read at construction time
123+
3. **Defaults** — info level, text format, no Prometheus push
124+
125+
When `f1.WithLogger(logger)` is used, the caller owns the logger entirely. In this case `WithLogLevel`, `WithLogFormat`, `F1_LOG_LEVEL` and `F1_LOG_FORMAT` have no effect.
126+
127+
```golang
128+
// Example: override push gateway and log level programmatically
129+
f1.New(
130+
f1.WithPrometheusPushGateway("http://pushgateway:9091"),
131+
f1.WithLogLevel("debug"),
132+
).AddScenario("myScenario", mySetup).Execute()
133+
134+
// Example: ignore all env vars, configure everything in code
135+
f1.New(
136+
f1.WithoutEnvSettings(),
137+
f1.WithLogLevel("warn"),
138+
f1.WithLogFormat("json"),
139+
).AddScenario("myScenario", mySetup).Execute()
140+
141+
// Example: use a custom logger (log level/format options are ignored)
142+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
143+
f1.New(
144+
f1.WithLogger(logger),
145+
).AddScenario("myScenario", mySetup).Execute()
146+
```
147+
102148
## Contributions
103149
If you'd like to help improve `f1`, please fork this repo and raise a PR!

0 commit comments

Comments
 (0)