Added message Logging

This commit is contained in:
2021-09-16 15:45:36 +02:00
parent 83bb549c41
commit 9ccd413399
2 changed files with 25 additions and 6 deletions

View File

@@ -63,6 +63,8 @@ type ClientCredentials struct {
Ping int `json:"ping"`
}
const format = "2006/01/02 15:04:05"
// Instance - get instance of xmpp service
func Instance() *XMPPService {
return &xmppService
@@ -141,8 +143,13 @@ func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
onlinePresencePacket.Status = rolingStockPresenceMessage
err := client.Send(onlinePresencePacket)
log.Printf("Sending online presence stanza: %v", err)
return err
if err != nil {
return err
}
log.Printf("<%v> sent online status", jid)
return nil
}
func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
@@ -172,7 +179,7 @@ func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
}
func handleMessage(s xmpp.Sender, p stanza.Packet) {
log.Printf("Handle message")
msg, ok := p.(stanza.Message)
if !ok {
log.Printf(" message not OK")
@@ -180,8 +187,9 @@ func handleMessage(s xmpp.Sender, p stanza.Packet) {
return
}
log.Printf("Received The message %v", msg)
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
log.Printf("<%v> received following message: %v", msg.To, msg.Body)
// _, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: `{"status": "OK"}`}
err := s.Send(reply)