LOG_LEVEL variable (#577)
This commit is contained in:
@@ -68,6 +68,7 @@ LABEL \
|
|||||||
org.opencontainers.image.description="VPN swiss-knife like client to tunnel to multiple VPN servers using OpenVPN, IPtables, DNS over TLS, Shadowsocks, an HTTP proxy and Alpine Linux"
|
org.opencontainers.image.description="VPN swiss-knife like client to tunnel to multiple VPN servers using OpenVPN, IPtables, DNS over TLS, Shadowsocks, an HTTP proxy and Alpine Linux"
|
||||||
ENV VPNSP=pia \
|
ENV VPNSP=pia \
|
||||||
VERSION_INFORMATION=on \
|
VERSION_INFORMATION=on \
|
||||||
|
LOG_LEVEL=info \
|
||||||
VPN_TYPE=openvpn \
|
VPN_TYPE=openvpn \
|
||||||
PROTOCOL=udp \
|
PROTOCOL=udp \
|
||||||
OPENVPN_VERSION=2.5 \
|
OPENVPN_VERSION=2.5 \
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
logger.PatchLevel(allSettings.Log.Level)
|
||||||
|
|
||||||
puid, pgid := allSettings.System.PUID, allSettings.System.PGID
|
puid, pgid := allSettings.System.PUID, allSettings.System.PGID
|
||||||
|
|
||||||
|
|||||||
30
internal/configuration/log.go
Normal file
30
internal/configuration/log.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package configuration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/qdm12/golibs/logging"
|
||||||
|
"github.com/qdm12/golibs/params"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Log struct {
|
||||||
|
Level logging.Level `json:"level"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (settings *Log) lines() (lines []string) {
|
||||||
|
lines = append(lines, lastIndent+"Log:")
|
||||||
|
|
||||||
|
lines = append(lines, indent+lastIndent+"Level: "+settings.Level.String())
|
||||||
|
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (settings *Log) read(env params.Interface) (err error) {
|
||||||
|
defaultLevel := logging.LevelInfo.String()
|
||||||
|
settings.Level, err = env.LogLevel("LOG_LEVEL", params.Default(defaultLevel))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("environment variable LOG_LEVEL: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ type Settings struct {
|
|||||||
VersionInformation bool
|
VersionInformation bool
|
||||||
ControlServer ControlServer
|
ControlServer ControlServer
|
||||||
Health Health
|
Health Health
|
||||||
|
Log Log
|
||||||
}
|
}
|
||||||
|
|
||||||
func (settings *Settings) String() string {
|
func (settings *Settings) String() string {
|
||||||
@@ -33,6 +34,7 @@ func (settings *Settings) lines() (lines []string) {
|
|||||||
lines = append(lines, settings.VPN.lines()...)
|
lines = append(lines, settings.VPN.lines()...)
|
||||||
lines = append(lines, settings.DNS.lines()...)
|
lines = append(lines, settings.DNS.lines()...)
|
||||||
lines = append(lines, settings.Firewall.lines()...)
|
lines = append(lines, settings.Firewall.lines()...)
|
||||||
|
lines = append(lines, settings.Log.lines()...)
|
||||||
lines = append(lines, settings.System.lines()...)
|
lines = append(lines, settings.System.lines()...)
|
||||||
lines = append(lines, settings.HTTPProxy.lines()...)
|
lines = append(lines, settings.HTTPProxy.lines()...)
|
||||||
lines = append(lines, settings.ShadowSocks.lines()...)
|
lines = append(lines, settings.ShadowSocks.lines()...)
|
||||||
@@ -57,6 +59,7 @@ var (
|
|||||||
ErrUpdater = errors.New("cannot read Updater settings")
|
ErrUpdater = errors.New("cannot read Updater settings")
|
||||||
ErrPublicIP = errors.New("cannot read Public IP getter settings")
|
ErrPublicIP = errors.New("cannot read Public IP getter settings")
|
||||||
ErrHealth = errors.New("cannot read health settings")
|
ErrHealth = errors.New("cannot read health settings")
|
||||||
|
ErrLog = errors.New("cannot read log settings")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Read obtains all configuration options for the program and returns an error as soon
|
// Read obtains all configuration options for the program and returns an error as soon
|
||||||
@@ -113,5 +116,9 @@ func (settings *Settings) Read(env params.Interface, logger logging.Logger) (err
|
|||||||
return fmt.Errorf("%w: %s", ErrHealth, err)
|
return fmt.Errorf("%w: %s", ErrHealth, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := settings.Log.read(r.env); err != nil {
|
||||||
|
return fmt.Errorf("%w: %s", ErrLog, err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ func Test_Settings_lines(t *testing.T) {
|
|||||||
" |--Protocol: udp",
|
" |--Protocol: udp",
|
||||||
"|--DNS:",
|
"|--DNS:",
|
||||||
"|--Firewall: disabled ⚠️",
|
"|--Firewall: disabled ⚠️",
|
||||||
|
"|--Log:",
|
||||||
|
" |--Level: DEBUG",
|
||||||
"|--System:",
|
"|--System:",
|
||||||
" |--Process user ID: 0",
|
" |--Process user ID: 0",
|
||||||
" |--Process group ID: 0",
|
" |--Process group ID: 0",
|
||||||
|
|||||||
Reference in New Issue
Block a user