Skip to content

Instantly share code, notes, and snippets.

@wcalderipe
Last active January 10, 2019 00:17
Show Gist options
  • Save wcalderipe/3798b43d1b304914ce635e423cfdc81d to your computer and use it in GitHub Desktop.
Save wcalderipe/3798b43d1b304914ce635e423cfdc81d to your computer and use it in GitHub Desktop.
Logger

Logger

Interface suggestion

import { logger, Level } from 'booking-flow-logger'

logger({
  level: Level.INFO,
  tracking: {
    flowId: 'flow-id',
    trackId: 'track-id',
    home: 'es_cl'
  },
  action: 'currencies.controller.get',
  description: 'lorem ipsum dolor',
  query: {
    fromCurrency: 'USD',
    toCurrency: 'CLP'
  }
})

// -> level="INFO" flwid="flow-id" trkid="track-id" home="es_cl" action="currencies.controller.get" description="lorem ipsum dolor" query="'{'fromCurrency':'USD','toCurrency':'CLP'}'"

// This is an alias for the logger({ level: Level.INFO })
logger.info({ /* Log data */ })
logger.error({ /* Log data */ })

// In the test

import { spy } from 'sinon'
import { logger } from 'booking-flow-logger'

describe('test logger in some component', () => {
  test('logs query params from request', () => {
    spy(logger, 'info')
    
    expect(logger.info).toHaveBeenCalledWith({
      // assert the object passed to the logger instead of a string
    })
  })
})

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment