From 9b6caf4e62868edd4acc8265e66ecbc1e94d508c Mon Sep 17 00:00:00 2001 From: ycc Date: Wed, 5 Jun 2024 22:23:48 +0200 Subject: [PATCH] adding loggers --- client/helpers/logger.go | 12 ++++++++++++ client/logger.go | 12 ++++++++++++ client/peer.go | 5 ++--- client/server.go | 5 ++--- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 client/helpers/logger.go create mode 100644 client/logger.go diff --git a/client/helpers/logger.go b/client/helpers/logger.go new file mode 100644 index 0000000..aa497e2 --- /dev/null +++ b/client/helpers/logger.go @@ -0,0 +1,12 @@ +package helpers + +import ( + "github.com/rs/zerolog" +) + +var logger zerolog.Logger + +// AddLogger sets the logger for the sublibrary +func AddLogger(l zerolog.Logger) { + logger = l +} diff --git a/client/logger.go b/client/logger.go new file mode 100644 index 0000000..65f6343 --- /dev/null +++ b/client/logger.go @@ -0,0 +1,12 @@ +package client + +import ( + "github.com/rs/zerolog" +) + +var logger zerolog.Logger + +// AddLogger sets the logger for the sublibrary +func AddLogger(l zerolog.Logger) { + logger = l +} diff --git a/client/peer.go b/client/peer.go index 0bbfe7b..58276b6 100644 --- a/client/peer.go +++ b/client/peer.go @@ -1,7 +1,6 @@ package client import ( - "fmt" "io" "os" "time" @@ -206,7 +205,7 @@ func (p *Peer) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, er // fmt.Println("[AsymEncryptMessage] Signature should be verified with:", p.MyIdentity.Public) enc, err := meowlib.AsymEncryptAndSign(p.ContactEncryption, p.MyIdentity.Private, Message) if err != nil { - fmt.Println(err.Error()) + logger.Error().Err(err).Msg("Peer.AsymEncryptMessage") return enc, err } return enc, err @@ -219,7 +218,7 @@ func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMe // fmt.Println("[AsymDecryptMessage] Signature will be verified with:", p.ContactPublicKey) DecryptedMessage, err = meowlib.AsymDecryptAndCheck(p.MyEncryptionKp.Private, p.ContactPublicKey, Message, Signature) if err != nil { - fmt.Println(err.Error()) + logger.Error().Err(err).Msg("Peer.AsymDecryptMessage") return nil, err } return DecryptedMessage, err diff --git a/client/server.go b/client/server.go index d8a42d2..ec2e176 100644 --- a/client/server.go +++ b/client/server.go @@ -1,7 +1,6 @@ package client import ( - "fmt" "strings" "time" @@ -119,7 +118,7 @@ func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessag var enc *meowlib.EncryptedMessage enc, err := meowlib.AsymEncryptAndSign(ints.PublicKey, ints.UserKp.Private, Message) if err != nil { - fmt.Println(err.Error()) + logger.Error().Err(err).Msg("Server.AsymEncryptMessage") return nil, err } return enc, err @@ -129,7 +128,7 @@ func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessag func (ints *Server) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) { DecryptedMessage, err = meowlib.AsymDecryptAndCheck(ints.UserKp.Private, ints.PublicKey, Message, Signature) if err != nil { - fmt.Println(err.Error()) + logger.Error().Err(err).Msg("Server.AsymDecryptMessage") return nil, err } return DecryptedMessage, err