aboutsummaryrefslogtreecommitdiff
path: root/internal/config/options.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2023-09-24 16:32:09 -0700
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-09-24 22:37:33 -0700
commitc0e954f19d707fef8ef8271636ec661634a4c4c7 (patch)
tree5aa052a048f470e233a454e5ad9071eed1fa37c0 /internal/config/options.go
parent54cb8fa0286e4a2f1a81c32b5a89722d93b30bf7 (diff)
downloadv2-c0e954f19d707fef8ef8271636ec661634a4c4c7.tar.gz
v2-c0e954f19d707fef8ef8271636ec661634a4c4c7.tar.zst
v2-c0e954f19d707fef8ef8271636ec661634a4c4c7.zip
Implement structured logging using log/slog package
Diffstat (limited to 'internal/config/options.go')
-rw-r--r--internal/config/options.go39
1 files changed, 31 insertions, 8 deletions
diff --git a/internal/config/options.go b/internal/config/options.go
index 16d16cbd..11a4ac2c 100644
--- a/internal/config/options.go
+++ b/internal/config/options.go
@@ -15,7 +15,10 @@ import (
const (
defaultHTTPS = false
+ defaultLogFile = "stderr"
defaultLogDateTime = false
+ defaultLogFormat = "text"
+ defaultLogLevel = "info"
defaultHSTS = true
defaultHTTPService = true
defaultSchedulerService = true
@@ -91,11 +94,13 @@ type Option struct {
// Options contains configuration options.
type Options struct {
HTTPS bool
+ logFile string
logDateTime bool
+ logFormat string
+ logLevel string
hsts bool
httpService bool
schedulerService bool
- debug bool
serverTimingHeader bool
baseURL string
rootURL string
@@ -165,11 +170,13 @@ func NewOptions() *Options {
return &Options{
HTTPS: defaultHTTPS,
+ logFile: defaultLogFile,
logDateTime: defaultLogDateTime,
+ logFormat: defaultLogFormat,
+ logLevel: defaultLogLevel,
hsts: defaultHSTS,
httpService: defaultHTTPService,
schedulerService: defaultSchedulerService,
- debug: defaultDebug,
serverTimingHeader: defaultTiming,
baseURL: defaultBaseURL,
rootURL: defaultRootURL,
@@ -231,11 +238,30 @@ func NewOptions() *Options {
}
}
+func (o *Options) LogFile() string {
+ return o.logFile
+}
+
// LogDateTime returns true if the date/time should be displayed in log messages.
func (o *Options) LogDateTime() bool {
return o.logDateTime
}
+// LogFormat returns the log format.
+func (o *Options) LogFormat() string {
+ return o.logFormat
+}
+
+// LogLevel returns the log level.
+func (o *Options) LogLevel() string {
+ return o.logLevel
+}
+
+// SetLogLevel sets the log level.
+func (o *Options) SetLogLevel(level string) {
+ o.logLevel = level
+}
+
// HasMaintenanceMode returns true if maintenance mode is enabled.
func (o *Options) HasMaintenanceMode() bool {
return o.maintenanceMode
@@ -246,11 +272,6 @@ func (o *Options) MaintenanceMessage() string {
return o.maintenanceMessage
}
-// HasDebugMode returns true if debug mode is enabled.
-func (o *Options) HasDebugMode() bool {
- return o.debug
-}
-
// HasServerTimingHeader returns true if server-timing headers enabled.
func (o *Options) HasServerTimingHeader() bool {
return o.serverTimingHeader
@@ -593,7 +614,6 @@ func (o *Options) SortedOptions(redactSecret bool) []*Option {
"DATABASE_MAX_CONNS": o.databaseMaxConns,
"DATABASE_MIN_CONNS": o.databaseMinConns,
"DATABASE_URL": redactSecretValue(o.databaseURL, redactSecret),
- "DEBUG": o.debug,
"DISABLE_HSTS": !o.hsts,
"DISABLE_HTTP_SERVICE": !o.httpService,
"DISABLE_SCHEDULER_SERVICE": !o.schedulerService,
@@ -609,7 +629,10 @@ func (o *Options) SortedOptions(redactSecret bool) []*Option {
"INVIDIOUS_INSTANCE": o.invidiousInstance,
"KEY_FILE": o.certKeyFile,
"LISTEN_ADDR": o.listenAddr,
+ "LOG_FILE": o.logFile,
"LOG_DATE_TIME": o.logDateTime,
+ "LOG_FORMAT": o.logFormat,
+ "LOG_LEVEL": o.logLevel,
"MAINTENANCE_MESSAGE": o.maintenanceMessage,
"MAINTENANCE_MODE": o.maintenanceMode,
"METRICS_ALLOWED_NETWORKS": strings.Join(o.metricsAllowedNetworks, ","),