allow unsetting a log level through subcommand and add admin page for settng log level

This commit is contained in:
Mechiel Lukkien
2023-02-06 15:17:46 +01:00
parent 4202fbe108
commit 6cbe4d5d37
8 changed files with 212 additions and 7 deletions

View File

@ -66,10 +66,10 @@ type AccountDestination struct {
Destination config.Destination
}
// SetLogLevel sets a new log level for pkg. An empty pkg sets the default log
// LogLevelSet sets a new log level for pkg. An empty pkg sets the default log
// value that is used if no explicit log level is configured for a package.
// This change is ephemeral, no config file is changed.
func (c *Config) SetLogLevel(pkg string, level mlog.Level) {
func (c *Config) LogLevelSet(pkg string, level mlog.Level) {
c.logMutex.Lock()
defer c.logMutex.Unlock()
l := c.copyLogLevels()
@ -79,6 +79,17 @@ func (c *Config) SetLogLevel(pkg string, level mlog.Level) {
mlog.SetConfig(c.Log)
}
// LogLevelRemove removes a configured log level for a package.
func (c *Config) LogLevelRemove(pkg string) {
c.logMutex.Lock()
defer c.logMutex.Unlock()
l := c.copyLogLevels()
delete(l, pkg)
c.Log = l
xlog.Print("log level cleared", mlog.Field("pkg", pkg))
mlog.SetConfig(c.Log)
}
// copyLogLevels returns a copy of c.Log, for modifications.
// must be called with log lock held.
func (c *Config) copyLogLevels() map[string]mlog.Level {