diff options
author | Robin Jarry <robin@jarry.cc> | 2022-07-19 22:31:51 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-23 22:52:15 +0200 |
commit | cd1999555714fb886493d2d04b6c472be55cebef (patch) | |
tree | 1df3bcf5f687752db671d8bc9c7eab8a5c0fde71 /lib/crypto/gpg/gpgbin | |
parent | a1f779ccc9b16b22ad6cb2e0bf73c290fd0cc756 (diff) | |
download | aerc-cd1999555714fb886493d2d04b6c472be55cebef.tar.gz |
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 <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'lib/crypto/gpg/gpgbin')
-rw-r--r-- | lib/crypto/gpg/gpgbin/gpgbin.go | 33 |
1 files changed, 2 insertions, 31 deletions
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) -} |