diff --git a/lib/pam/pam.go b/lib/pam/pam.go index b6c70ddcb1267..4ea0b0ac4c071 100644 --- a/lib/pam/pam.go +++ b/lib/pam/pam.go @@ -47,6 +47,7 @@ import "C" import ( "bufio" + "context" "fmt" "io" "os" @@ -57,10 +58,10 @@ import ( "unsafe" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" "github.com/gravitational/teleport" "github.com/gravitational/teleport/lib/service/servicecfg" + logutils "github.com/gravitational/teleport/lib/utils/log" ) func init() { @@ -101,9 +102,7 @@ func init() { runtime.LockOSThread() } -var log = logrus.WithFields(logrus.Fields{ - teleport.ComponentKey: teleport.ComponentPAM, -}) +var logger = logutils.NewPackageLogger(teleport.ComponentKey, teleport.ComponentPAM) const ( // maxMessageSize is the maximum size of a message to accept from PAM. In @@ -148,7 +147,7 @@ var handlers map[int]handler = make(map[int]handler) func writeCallback(index C.int, stream C.int, s *C.char) { handle, err := lookupHandler(int(index)) if err != nil { - log.Errorf("Unable to write to output stream: %v", err) + logger.ErrorContext(context.Background(), "Unable to write to output stream", "error", err) return } @@ -164,7 +163,7 @@ func writeCallback(index C.int, stream C.int, s *C.char) { func readCallback(index C.int, e C.int) *C.char { handle, err := lookupHandler(int(index)) if err != nil { - log.Errorf("Unable to read from input stream: %v", err) + logger.ErrorContext(context.Background(), "Unable to read from input stream", "error", err) return nil } @@ -176,7 +175,7 @@ func readCallback(index C.int, e C.int) *C.char { // Read from the stream (typically stdin or equivalent). s, err := handle.readStream(echo) if err != nil { - log.Errorf("Unable to read from input stream: %v", err) + logger.ErrorContext(context.Background(), "Unable to read from input stream", "error", err) return nil } @@ -438,7 +437,7 @@ func (p *PAM) free() { // Terminate the PAM transaction. retval := C._pam_end(pamHandle, p.pamh, p.retval) if retval != C.PAM_SUCCESS { - log.Warnf("Failed to end PAM transaction: %v.\n", p.codeToError(retval)) + logger.WarnContext(context.Background(), "Failed to end PAM transaction", "error", p.codeToError(retval)) } // Release the memory allocated for the conversation function.