support for json logs #290 (#291)

* support for json logs #290
This commit is contained in:
Marc Brugger
2024-01-26 09:14:41 +01:00
committed by GitHub
parent 5da3730015
commit d262357c87
3 changed files with 21 additions and 4 deletions

View File

@@ -10,7 +10,8 @@ Synchronize [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome) config to
## FAQ & Deprecations
Please check the wiki
for [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ) and [Deprecations](https://github.com/bakito/adguardhome-sync/wiki/Deprecations).
for [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ)
and [Deprecations](https://github.com/bakito/adguardhome-sync/wiki/Deprecations).
## Current sync features
@@ -253,7 +254,7 @@ features:
## Log Level
The log level can be set with the environment variable: LOG_LEVEL
The log level can be set with the environment variable: `LOG_LEVEL`
The following log levels are supported (default: info)
@@ -261,3 +262,8 @@ The following log levels are supported (default: info)
- info
- warn
- error
## Log Format
Default log format is `console`.
It can be changed to `json`by setting the environment variable: `LOG_FORMAT=json`

View File

@@ -10,6 +10,7 @@ import (
const (
logHistorySize = 50
envLogLevel = "LOG_LEVEL"
envLogFormat = "LOG_FORMAT"
)
var (
@@ -31,14 +32,23 @@ func init() {
}
}
format := "console"
if fmt, ok := os.LookupEnv(envLogFormat); ok {
format = fmt
}
cfg := zap.Config{
Level: zap.NewAtomicLevelAt(level),
Development: false,
Encoding: "console",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
Encoding: format,
EncoderConfig: zap.NewProductionEncoderConfig(),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
cfg.EncoderConfig.EncodeDuration = zapcore.StringDurationEncoder
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
opt := zap.WrapCore(func(c zapcore.Core) zapcore.Core {
return zapcore.NewTee(c, &logList{
enc: zapcore.NewConsoleEncoder(cfg.EncoderConfig),

View File

@@ -6,6 +6,7 @@ metadata:
namespace: {{ .Release.Namespace }}
data:
API_PORT: '0'
LOG_FORMAT: json
ORIGIN_URL: 'http://service-origin.{{ $.Release.Namespace }}.svc.cluster.local:3000'
ORIGIN_PASSWORD: 'password'
ORIGIN_USERNAME: 'username'