Skip to content

Bug: regression - not possible to log arbitrary objects #880

Closed
@dreamorosi

Description

@dreamorosi

Bug description

After the refactoring introduced in #614 the Logger utility only allows to log values that are of type Error or string.

As such it's not possible anymore to log an arbitrary object, which causes unneeded friction since the point of logger is to promote structured logging.

As a trivial example, I might want to log the event of my function:

logger.debug('Lambda invoked', {
  event: { event }
});

This causes compile errors when using TypeScript (see below for details).

Expected Behavior

  1. Types allow passing strings, Error, and arbitrary objects
  2. Logger parses/structures each type correctly (i.e. strings are appended to a key & not broken down like it used to happen here, Error objects are broken down correctly, other types of objects are appended)

Current Behavior

Argument of type '[{ details: { event: APIGatewayRequestAuthorizerEvent; }; }]' is not assignable to parameter of type 'LogItemExtraInput'.
  Type '[{ details: { event: APIGatewayRequestAuthorizerEvent; }; }]' is not assignable to type '[string | Error]'.
    Type '{ details: { event: APIGatewayRequestAuthorizerEvent; }; }' is not assignable to type 'string | Error'.
      Object literal may only specify known properties, and 'details' does not exist in type 'Error'.ts(2345)

Possible Solution

N/A

Steps to Reproduce

import { APIGatewayRequestAuthorizerEvent } from 'aws-lambda';
import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ logLevel: 'DEBUG' });

export const handler = async (event:  APIGatewayRequestAuthorizerEvent) => {
  
  logger.debug('Lambda invoked', {
    details: { event }
  });

  return;
};

image

Environment

  • Powertools version used: v0.9.0
  • Packaging format (Layers, npm): npm
  • AWS Lambda function runtime: N/A
  • Debugging logs: N/A

Related issues, RFCs

#565
#614

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompletedThis item is complete and has been merged/shippedloggerThis item relates to the Logger Utility

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions