diff options
| author | Shulhan <ms@kilabit.info> | 2023-11-23 11:02:05 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-11-25 01:33:07 +0700 |
| commit | a9701f66c2e38a3a7f3d12deed6ebba5144e208e (patch) | |
| tree | 0f4300ba3d35b353b1b0f629a406aa00d563d4fa | |
| parent | d507104c77d6d8bd6b00cc610e8710d326ecd11e (diff) | |
| download | awwan-a9701f66c2e38a3a7f3d12deed6ebba5144e208e.tar.xz | |
all: print non error information using package log instead of fmt
Although log print to stderr, this allow user to filter between awwan
output and command output, for example by piping stderr to /dev/null
$ awwan env-get "key" dir/ 2>/dev/null
The output env-get is not poluted by other logs.
| -rw-r--r-- | awwan.go | 3 | ||||
| -rw-r--r-- | crypto_context.go | 6 | ||||
| -rw-r--r-- | http_server.go | 3 | ||||
| -rw-r--r-- | session.go | 4 |
4 files changed, 9 insertions, 7 deletions
@@ -5,6 +5,7 @@ package awwan import ( "fmt" + "log" "os" "path/filepath" "strings" @@ -93,7 +94,7 @@ func (aww *Awwan) init(baseDir string) (err error) { return err } - fmt.Printf("--- BaseDir: %s\n", aww.BaseDir) + log.Printf(`--- BaseDir: %s`, aww.BaseDir) aww.cryptoc = newCryptoContext(aww.BaseDir) diff --git a/crypto_context.go b/crypto_context.go index 37b3aff..40d1e82 100644 --- a/crypto_context.go +++ b/crypto_context.go @@ -14,6 +14,7 @@ import ( "hash" "io" "io/fs" + "log" "os" "path/filepath" @@ -121,7 +122,7 @@ func (cryptoc *cryptoContext) loadPrivateKey() (err error) { return err } - fmt.Printf("--- Loading private key file %q (enter to skip passphrase) ...\n", + log.Printf(`--- Loading private key file %q (enter to skip passphrase) ...`, relativePath(cryptoc.baseDir, fileKey)) if len(pass) == 0 { @@ -165,8 +166,7 @@ func (cryptoc *cryptoContext) loadPassphrase() (pass []byte, err error) { return nil, fmt.Errorf(`%s: %w`, logp, err) } - fmt.Printf("--- Loading passphrase file %q ...\n", - relativePath(cryptoc.baseDir, filePass)) + log.Printf(`--- Loading passphrase file %q ...`, relativePath(cryptoc.baseDir, filePass)) pass, err = os.ReadFile(filePass) if err != nil { diff --git a/http_server.go b/http_server.go index 009b821..04ac90a 100644 --- a/http_server.go +++ b/http_server.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io/fs" + "log" "net/http" "os" "path" @@ -178,7 +179,7 @@ func (httpd *httpServer) registerEndpoints() (err error) { // start the HTTP server. func (httpd *httpServer) start() (err error) { - fmt.Printf("--- Starting HTTP server at http://%s\n", httpd.Server.Options.Address) + log.Printf(`--- Starting HTTP server at http://%s`, httpd.Server.Options.Address) return httpd.Server.Start() } @@ -57,7 +57,7 @@ func NewSession(aww *Awwan, sessionDir string) (ses *Session, err error) { randomString string ) - fmt.Printf("--- NewSession %q\n", relativePath(aww.BaseDir, sessionDir)) + log.Printf(`--- NewSession %q`, relativePath(aww.BaseDir, sessionDir)) ses = &Session{ cryptoc: aww.cryptoc, @@ -681,7 +681,7 @@ func (ses *Session) loadFileEnv(awwanEnv string, isVault bool) (err error) { return fmt.Errorf(`%s: %w`, relPath, err) } - fmt.Printf("--- Loading %q ...\n", relativePath(ses.BaseDir, awwanEnv)) + log.Printf(`--- Loading %q ...`, relativePath(ses.BaseDir, awwanEnv)) if isVault { content, err = ses.cryptoc.decrypt(content) |
