dherault / dherault/serverless-offline

Logs in golang are not displayed in the console (Windows)

Open
#1,352 10 comments 1 reaction 1 assignee Claimed by @DorianMazur View on GitHub
bug
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## Bug Report

I'm facing a weird behavior with golang and serverless-offline on windows; any log produced with the standard packages `log` and `fmt` are not shown in the console and some of them are sent as the HTTP response when the lambda is triggered as an HTTP endpoint.

**Current Behavior**

- Invokations to any logging method from the `log` standard package end up in the HTTP response. Methods like `log.Print` or `log.Println`. The logs are not shown in the console.
- Invocations to any logging method from the `fmt` standard package causes a 502 HTTP response. The logs are not shown in the console.

**Sample Code**

- file: serverless.yml

```yaml
service: golang-sls-offline-windows-bug

frameworkVersion: '3'

provider:
name: aws
runtime: go1.x
stage: ${opt:stage, 'dev'}
region: us-west-2

functions:
myService:
handler: ./services/my_service.go
events:
- http:
path: /
method: get
plugins:
- serverless-offline

package:
individually: true
```

- file: services/my_service.go

```go
package main

import (
"context"
"log"

"github.com/aws/aws-lambda-go/events"
)

func HandleRequest(context.Context, events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Print("This is printed as the http response :(") // Change this with fmt.Println and you will have a 502 🙁

// This HTTP result is never sent
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: `{"message": "Hello serverless world"}`,
Headers: map[string]string{
"Content-Type": "application/json",
},
}, nil
}

func main() {
fmt.Println("Hello, world!")
}
```

**Expected behavior/code**

The logs from `log.Print` and `fmt.Println` should be shown in the console. They should not be shown as the HTTP response or break the service by returning 502 Status code.

**Environment**

- `serverless` version: 3.7.1
- `serverless-offline` version: ^8.5.0
- `node.js` version: 14.19.0
- `OS`: Windows 11

_optional, if you are using any of the following frameworks to invoke handlers_

- `go` version: 1.7

**Possible Solution**

**Additional context/Screenshots**

- The `log.Print` being showed in Postman as the HTTP response:

- The `fmt.Println` causing 502 status code:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.