middyjs / middy

🛵 The stylish Node.js middleware engine for AWS Lambda 🛵

Home Page:https://middy.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

input-output-logger: replacer function is not called

iloewensen opened this issue · comments

Describe the bug
The replacer function of input-output-logger middleware is not called

To Reproduce

test('It should call replacer', async (t) => {
  const logger = sinon.spy()
  const replacer = sinon.spy()

  const handler = middy((event) => event).use(
    inputOutputLogger({
      logger,
      replacer
    })
  )

  const event = { foo: 'bar', fuu: 'baz' }
  const response = await handler(event, context)

  t.true(logger.calledWithExactly({ event }))
  t.true(logger.calledWithExactly({ response: event }))
  t.true(replacer.calledWith({ event }))
  t.deepEqual(response, event)
})

Expected behaviour
The replacer is called

Environment

  • Node.js: 20.12
  • Middy: 5.3.2

Additional context

Thanks for reporting. In v4 we used JSON.parse(JSON.stringify(message, replacer)) to deep clone the object. In v5 we use the newer structuredClone(message). The replacer option should have been removed in v5, sorry about the confusion.

@willfarrell it would be helpful to update the documentation :)
https://middy.js.org/docs/middlewares/input-output-logger

I've now triggered the docs to rebuild.