Skip to content

Logger doesn't write to stdout/stderr by default resulting invalid JSON log entries in CloudWatchΒ #241

@klindklind

Description

@klindklind

This is a Bug Report

Description

We switched from Winston to use your logger because it has many features we need out of the box. But then we realized that the loggings are not pure JSON anymore.

  • What went wrong?
    Logs ingested into CloudWatch from our lambda which uses power-logger are not pure JSON. There is a row of plaintext metadata at the beginning of each log entry.

Implementation:

import log from '@dazn/lambda-powertools-logger'

log.info('foo', { bar: 'jar' })

will result in CloudWatch log like:

2020-12-03T09:59:57.754Z	4220ab3e-0559-4a5f-a318-d7b33be19925	INFO	
{
    "message": "foo",
    "data": {
        "bar": "jar"
    },
    "awsRegion": "eu-west-1",
    "functionName": "my-function",
    "functionVersion": "$LATEST",
    "functionMemorySize": "192",
     ... etc. metadata
}
  • What did you expect should have happened?
    Only JSON
{
    "message": "foo",
    "data": {
        "bar": "jar"
    },
    "awsRegion": "eu-west-1",
    "functionName": "my-function",
    "functionVersion": "$LATEST",
    "functionMemorySize": "192",
     ... etc. metadata
}

should've been logged into CloudWatch.

  • Workaround
    We forked the lambda-powertools-logger to explicitly log into process.stdout/.stderr. Could probably open a PR if your intention is to log pure JSON?

Additional Data

  • Which powertool package are you using?: lambda-powertools-logger
  • Which version are you using?: lambda-powertools-logger: 1.24.1
  • Middy engine version you're using: 1.4.0
  • Operating System: Lambda runtime Node 12.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions