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 --- lib/crypto/gpg/gpgbin/gpgbin.go | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'lib/crypto/gpg/gpgbin/gpgbin.go') diff --git a/lib/crypto/gpg/gpgbin/gpgbin.go b/lib/crypto/gpg/gpgbin/gpgbin.go index 9f79e972..2eb83dc9 100644 --- a/lib/crypto/gpg/gpgbin/gpgbin.go +++ b/lib/crypto/gpg/gpgbin/gpgbin.go @@ -6,15 +6,12 @@ import ( "errors" "fmt" "io" - "io/ioutil" - "log" - "os" "os/exec" "strconv" "strings" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" - "github.com/mattn/go-isatty" ) // gpg represents a gpg command with buffers attached to stdout and stderr @@ -112,17 +109,6 @@ func longKeyToUint64(key string) (uint64, error) { // parse parses the output of gpg --status-fd func parse(r io.Reader, md *models.MessageDetails) error { - var ( - logOut io.Writer - logger *log.Logger - ) - if !isatty.IsTerminal(os.Stdout.Fd()) { - logOut = os.Stdout - } else { - logOut = ioutil.Discard - os.Stdout, _ = os.Open(os.DevNull) - } - logger = log.New(logOut, "", log.LstdFlags) var err error var msgContent []byte var msgCollecting bool @@ -135,7 +121,7 @@ func parse(r io.Reader, md *models.MessageDetails) error { } if strings.HasPrefix(line, "[GNUPG:]") { msgCollecting = false - logger.Println(line) + logging.Debugf(line) } if msgCollecting { msgContent = append(msgContent, scanner.Bytes()...) @@ -270,18 +256,3 @@ var micalgs = map[int]string{ 10: "pgp-sha512", 11: "pgp-sha224", } - -func logger(s string) { - var ( - logOut io.Writer - logger *log.Logger - ) - if !isatty.IsTerminal(os.Stdout.Fd()) { - logOut = os.Stdout - } else { - logOut = ioutil.Discard - os.Stdout, _ = os.Open(os.DevNull) - } - logger = log.New(logOut, "", log.LstdFlags) - logger.Println(s) -} -- cgit