Skip to content

Commit

Permalink
Remove newlines from log messages
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Dec 9, 2024
1 parent b94918c commit d9418fe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
messageHandler := func(msg *stan.Msg) {
i := atomic.AddUint64(&counter, 1)

log.Printf("[#%d] Received on [%s]: '%s'\n", i, msg.Subject, msg)
log.Printf("[#%d] Received on [%s]: '%s'", i, msg.Subject, msg)

started := time.Now()

Expand All @@ -60,7 +60,7 @@ func main() {
xCallID := req.Header.Get("X-Call-Id")

functionURL := makeFunctionURL(&req, &config, req.Path, req.QueryString)
fmt.Printf("[#%d] Invoking: %s with %d bytes, via: %s\n", i, req.Function, len(req.Body), functionURL)
fmt.Printf("[#%d] Invoking: %s with %d bytes, via: %s", i, req.Function, len(req.Body), functionURL)

if config.DebugPrintBody {
fmt.Println(string(req.Body))
Expand All @@ -73,6 +73,8 @@ func main() {
return
}

req.Header.Set("User-Agent", "openfaas-ce/nats-queue-worker")

defer request.Body.Close()
copyHeaders(request.Header, &req.Header)

Expand Down Expand Up @@ -110,7 +112,7 @@ func main() {
timeTaken)

if err != nil {
log.Printf("[#%d] Posted callback to: %s - status %d, error: %s\n", i, req.CallbackURL.String(), http.StatusServiceUnavailable, err.Error())
log.Printf("[#%d] Posted callback to: %s - status %d, error: %s", i, req.CallbackURL.String(), http.StatusServiceUnavailable, err.Error())
} else {
log.Printf("[#%d] Posted result to %s - status: %d", i, req.CallbackURL.String(), resultStatusCode)
}
Expand All @@ -132,14 +134,14 @@ func main() {
if config.WriteDebug {
fmt.Println(string(functionResult))
} else {
fmt.Printf("[#%d] %s returned %d bytes\n", i, req.Function, len(functionResult))
fmt.Printf("[#%d] %s returned %d bytes", i, req.Function, len(functionResult))
}
}

timeTaken := time.Since(started).Seconds()

if req.CallbackURL != nil {
log.Printf("[#%d] Callback to: %s\n", i, req.CallbackURL.String())
log.Printf("[#%d] Callback to: %s", i, req.CallbackURL.String())

resultStatusCode, err := postResult(&client,
res,
Expand All @@ -151,7 +153,7 @@ func main() {
timeTaken)

if err != nil {
log.Printf("[#%d] Error posting to callback-url: %s\n", i, err)
log.Printf("[#%d] Error posting to callback-url: %s", i, err)
} else {
log.Printf("[#%d] Posted result for %s to callback-url: %s, status: %d", i, req.Function, req.CallbackURL.String(), resultStatusCode)
}
Expand Down Expand Up @@ -190,7 +192,7 @@ func main() {

fmt.Printf("\nReceived an interrupt, unsubscribing and closing connection...\n\n")
if err := natsQueue.closeConnection(); err != nil {
log.Panicf("Cannot close connection to %s because of an error: %v\n", natsQueue.natsURL, err)
log.Panicf("Cannot close connection to %s because of an error: %v", natsQueue.natsURL, err)
}
close(signalChan)
}
Expand Down

0 comments on commit d9418fe

Please sign in to comment.