From cd1999555714fb886493d2d04b6c472be55cebef Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 19 Jul 2022 22:31:51 +0200 Subject: logging: use level-based logger functions Do not pass logger objects around anymore. Shuffle some messages to make them consistent with the new logging API. Avoid using %v when a more specific verb exists for the argument types. The loggers are completely disabled (i.e. Sprintf is not even called) by default. They are only enabled when redirecting stdout to a file. Signed-off-by: Robin Jarry Acked-by: Moritz Poldrack --- config/config.go | 9 +++++---- config/triggers.go | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'config') diff --git a/config/config.go b/config/config.go index ebdee5e..22bbe2b 100644 --- a/config/config.go +++ b/config/config.go @@ -23,6 +23,7 @@ import ( "github.com/mitchellh/go-homedir" "git.sr.ht/~rjarry/aerc/lib/templates" + "git.sr.ht/~rjarry/aerc/logging" ) type GeneralConfig struct { @@ -649,7 +650,7 @@ func validatePgpProvider(section *ini.Section) error { return nil } -func LoadConfigFromFile(root *string, logger *log.Logger) (*AercConfig, error) { +func LoadConfigFromFile(root *string) (*AercConfig, error) { if root == nil { _root := path.Join(xdg.ConfigHome(), "aerc") root = &_root @@ -837,7 +838,7 @@ func LoadConfigFromFile(root *string, logger *log.Logger) (*AercConfig, error) { } if baseOnly { - err = config.LoadBinds(binds, baseSectionName, group, logger) + err = config.LoadBinds(binds, baseSectionName, group) if err != nil { return nil, err } @@ -887,7 +888,7 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { return bindings, nil } -func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings, logger *log.Logger) error { +func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings) error { if sec, err := binds.GetSection(baseName); err == nil { binds, err := LoadBindingSection(sec) @@ -942,7 +943,7 @@ func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup } } if !valid { - logger.Printf("Tried to define binds for unexistent account: %v\n", acctName) + logging.Warnf("binds.conf: unexistent account: %s", acctName) continue } contextualBind.ContextType = BIND_CONTEXT_ACCOUNT diff --git a/config/triggers.go b/config/triggers.go index 3005d59..daf4373 100644 --- a/config/triggers.go +++ b/config/triggers.go @@ -7,6 +7,7 @@ import ( "github.com/google/shlex" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" ) @@ -52,6 +53,6 @@ func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig, return fmt.Sprintf(formatstr, args...), nil }) if err != nil { - fmt.Printf("Error from the new-email trigger: %s\n", err) + logging.Errorf("failed to run new-email trigger: %v", err) } } -- cgit v1.2.3