From f792675ebe8c7c3a6493d1d407c2abe6e0da1955 Mon Sep 17 00:00:00 2001 From: postmannen Date: Fri, 26 Mar 2021 05:13:51 +0100 Subject: [PATCH] cleaned up err console logging --- getmessagefromfile.go | 2 -- process.go | 13 ------------- ringbuffer.go | 4 ---- server.go | 5 ++--- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/getmessagefromfile.go b/getmessagefromfile.go index 37f98d5..77303be 100644 --- a/getmessagefromfile.go +++ b/getmessagefromfile.go @@ -36,7 +36,6 @@ func (s *server) getMessagesFromFile(directoryToCheck string, fileName string, i js, err := jsonFromFileData(b) if err != nil { er := fmt.Errorf("error: malformed json: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(s.nodeName), er) continue } @@ -52,7 +51,6 @@ func (s *server) getMessagesFromFile(directoryToCheck string, fileName string, i inputFromFileCh <- js } er := fmt.Errorf("error: getMessagesFromFile stopped") - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(s.nodeName), er) } diff --git a/process.go b/process.go index e216005..4e62182 100644 --- a/process.go +++ b/process.go @@ -135,7 +135,6 @@ func (p process) spawnWorker(s *server) { err := p.procFunc() if err != nil { er := fmt.Errorf("error: spawnWorker: procFunc failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(p.newMessagesCh, node(p.node), er) } }() @@ -156,7 +155,6 @@ func (p process) spawnWorker(s *server) { err := p.procFunc() if err != nil { er := fmt.Errorf("error: spawnWorker: procFunc failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(p.newMessagesCh, node(p.node), er) } }() @@ -176,7 +174,6 @@ func (p process) messageDeliverNats(natsConn *nats.Conn, message Message) { dataPayload, err := gobEncodeMessage(message) if err != nil { er := fmt.Errorf("error: createDataPayload: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(p.newMessagesCh, node(p.node), er) continue } @@ -198,7 +195,6 @@ func (p process) messageDeliverNats(natsConn *nats.Conn, message Message) { subReply, err := natsConn.SubscribeSync(msg.Reply) if err != nil { er := fmt.Errorf("error: nc.SubscribeSync failed: failed to create reply message: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(p.newMessagesCh, node(p.node), er) continue } @@ -207,7 +203,6 @@ func (p process) messageDeliverNats(natsConn *nats.Conn, message Message) { err = natsConn.PublishMsg(msg) if err != nil { er := fmt.Errorf("error: publish failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(p.newMessagesCh, node(p.node), er) continue } @@ -266,7 +261,6 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na err := gobDec.Decode(&message) if err != nil { er := fmt.Errorf("error: gob decoding failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } @@ -275,7 +269,6 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na mh, ok := p.methodsAvailable.CheckIfExists(message.Method) if !ok { er := fmt.Errorf("error: subscriberHandler: method type not available: %v", p.subject.CommandOrEvent) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } @@ -295,12 +288,10 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na if err != nil { er := fmt.Errorf("error: subscriberHandler: failed to execute event: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } } else { er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } @@ -311,7 +302,6 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na mf, ok := p.methodsAvailable.CheckIfExists(message.Method) if !ok { er := fmt.Errorf("error: subscriberHandler: method type not available: %v", p.subject.CommandOrEvent) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } @@ -332,18 +322,15 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na if err != nil { er := fmt.Errorf("error: subscriberHandler: failed to execute event: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } } else { er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } // --- default: er := fmt.Errorf("info: did not find that specific type of command: %#v", p.subject.CommandOrEvent) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(thisNode), er) } diff --git a/ringbuffer.go b/ringbuffer.go index a4a8355..a7d29ca 100644 --- a/ringbuffer.go +++ b/ringbuffer.go @@ -91,7 +91,6 @@ func (r *ringBuffer) fillBuffer(inCh chan subjectAndMessage, samValueBucket stri s, err := r.dumpBucket(samValueBucket) if err != nil { er := fmt.Errorf("error: fillBuffer: retreival of values from k/v store failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(r.newMessagesCh, node(r.nodeName), er) } @@ -116,7 +115,6 @@ func (r *ringBuffer) fillBuffer(inCh chan subjectAndMessage, samValueBucket stri // Check if the command or event exists in commandOrEvent.go if !coeAvailable.CheckIfExists(v.CommandOrEvent, v.Subject) { er := fmt.Errorf("error: fillBuffer: the event or command type do not exist, so this message will not be put on the buffer to be processed. Check the syntax used in the json file for the message. Allowed values are : %v", coeAvailableValues) - log.Printf("%v\n", er) sendErrorLogMessage(r.newMessagesCh, node(r.nodeName), er) fmt.Println() @@ -150,7 +148,6 @@ func (r *ringBuffer) fillBuffer(inCh chan subjectAndMessage, samValueBucket stri js, err := json.Marshal(samV) if err != nil { er := fmt.Errorf("error:fillBuffer gob encoding samValue: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(r.newMessagesCh, node(r.nodeName), er) } @@ -158,7 +155,6 @@ func (r *ringBuffer) fillBuffer(inCh chan subjectAndMessage, samValueBucket stri err = r.dbUpdate(r.db, samValueBucket, strconv.Itoa(dbID), js) if err != nil { er := fmt.Errorf("error: dbUpdate samValue failed: %v", err) - log.Printf("%v\n", er) sendErrorLogMessage(r.newMessagesCh, node(r.nodeName), er) } diff --git a/server.go b/server.go index 3cf71fc..c635b3e 100644 --- a/server.go +++ b/server.go @@ -151,7 +151,8 @@ func (s *server) printProcessesMap() { // sendErrorMessage will put the error message directly on the channel that is // read by the nats publishing functions. func sendErrorLogMessage(newMessagesCh chan<- []subjectAndMessage, FromNode node, theError error) { - // --- Testing + // NB: Adding log statement here for more visuality during development. + log.Printf("%v\n", theError) sam := createErrorMsgContent(FromNode, theError) newMessagesCh <- []subjectAndMessage{sam} } @@ -224,13 +225,11 @@ func (s *server) routeMessagesToProcess(dbFileName string, newSAM chan []subject // Check if the format of the message is correct. if _, ok := methodsAvailable.CheckIfExists(sam.Message.Method); !ok { er := fmt.Errorf("error: routeMessagesToProcess: the method do not exist, message dropped: %v", sam.Message.Method) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(s.nodeName), er) continue } if !coeAvailable.CheckIfExists(sam.Subject.CommandOrEvent, sam.Subject) { er := fmt.Errorf("error: routeMessagesToProcess: the command or event do not exist, message dropped: %v", sam.Message.Method) - log.Printf("%v\n", er) sendErrorLogMessage(s.newMessagesCh, node(s.nodeName), er) continue