golang println and log do not produce output in terminal

75 Views Asked by At

I am developing a project in Go. I frequently make calls to fmt.Println and log.Output to keep track of what is happening in my code. However, sometimes, the output from both of these does not appear in the output.

Here is an example of code in which this fault appears persistently.

func ClientLoginRequest(ctx *gin.Context) {
    // ...
    body, _ := auth.ProtectedResourceServerRequest(username, " get user details ", "/user") 
    jsonErr := json.Unmarshal(body, &models.UserServerItem)
    if jsonErr != nil {
        log.Output(1, "Failed to obtain user details")
    } else {
        log.Output(1, fmt.Sprintf("Setting current simulation to be %d", models.UserServerItem.CurrentSimulation))
        models.Users[username].CurrentSimulation = models.UserServerItem.CurrentSimulation
    }
    ctx.Redirect(http.StatusFound, "/user/dashboard")
}

The behavior is the same if the calls to log.Output are replaced by calls to fmt.Println.

There is no path that does not request the project to produce output. But no output occurs.

What should I do to ensure that the output of such statements appears in my terminal?

0

There are 0 best solutions below