pomerium/config/log.go
Caleb Doxsey f822c9a5d2
config: allow reloading of telemetry settings (#1255)
* metrics: support dynamic configuration settings

* add test

* trace: update configuration when settings change

* config: allow logging options to be configured when settings change

* envoy: allow changing log settings

* fix unexpected doc change

* fix tests

* pick a port at random

* update based on review
2020-08-12 08:14:15 -06:00

41 lines
775 B
Go

package config
import (
"sync"
"github.com/pomerium/pomerium/internal/log"
)
// The LogManager configures logging based on options.
type LogManager struct {
mu sync.Mutex
}
// NewLogManager creates a new LogManager.
func NewLogManager(src Source) *LogManager {
mgr := &LogManager{}
src.OnConfigChange(mgr.OnConfigChange)
mgr.OnConfigChange(src.GetConfig())
return mgr
}
// Close closes the log manager.
func (mgr *LogManager) Close() error {
return nil
}
// OnConfigChange is called whenever configuration changes.
func (mgr *LogManager) OnConfigChange(cfg *Config) {
mgr.mu.Lock()
defer mgr.mu.Unlock()
if cfg.Options.Debug {
log.EnableDebug()
} else {
log.DisableDebug()
}
if cfg.Options.LogLevel != "" {
log.SetLevel(cfg.Options.LogLevel)
}
}