How to use the @govuk-pay/pay-js-commons.logging function in @govuk-pay/pay-js-commons

To help you get started, we’ve selected a few @govuk-pay/pay-js-commons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alphagov / pay-frontend / app / middleware / logging_middleware.js View on Github external
const morgan = require('morgan')
const logger = require('../utils/logger')(__filename)
const { CORRELATION_HEADER } = require('../../config/correlation_header')
const { format } = require('@govuk-pay/pay-js-commons').logging.requestLogFormat(CORRELATION_HEADER)

module.exports = function () {
  return morgan(format, {
    stream: {
      write: message => {
        logger.info('Request received', JSON.parse(message))
      }
    }
  })
}
github alphagov / pay-selfservice / app / utils / response.js View on Github external
const _ = require('lodash')
const logger = require('./logger')(__filename)
const displayConverter = require('./display_converter')
const { CORRELATION_ID } = require('@govuk-pay/pay-js-commons').logging.keys

const ERROR_MESSAGE = 'There is a problem with the payments platform'
const ERROR_VIEW = 'error'

function response (req, res, template, data = {}) {
  let convertedData = displayConverter(req, data, template)
  render(req, res, template, convertedData)
}

function errorResponse (req, res, msg, status = 500) {
  if (!msg) msg = ERROR_MESSAGE
  let correlationId = req.correlationId
  if (typeof msg !== 'string') {
    msg = 'Please try again or contact support team.'
  }
  let data = { 'message': msg }
github alphagov / pay-selfservice / app / utils / logger.js View on Github external
const { createLogger, format, transports } = require('winston')
const { json, splat, prettyPrint } = format
const { govUkPayLoggingFormat } = require('@govuk-pay/pay-js-commons').logging
const { addSentryToErrorLevel } = require('./sentry.js')

const logger = createLogger({
  format: format.combine(
    splat(),
    prettyPrint(),
    govUkPayLoggingFormat({ container: 'selfservice', environment: process.env.ENVIRONMENT }),
    json()
  ),
  transports: [
    new transports.Console()
  ]
})

module.exports = (loggerName) => {
  const childLogger = logger.child({ logger_name: loggerName })
github alphagov / pay-frontend / app / utils / logger.js View on Github external
const { createLogger, format, transports } = require('winston')
const { json, splat, prettyPrint } = format
const { govUkPayLoggingFormat } = require('@govuk-pay/pay-js-commons').logging
const { addSentryToErrorLevel } = require('./sentry.js')

const logger = createLogger({
  format: format.combine(
    splat(),
    prettyPrint(),
    govUkPayLoggingFormat({ container: 'frontend', environment: process.env.ENVIRONMENT }),
    json()
  ),
  transports: [
    new transports.Console()
  ]
})

module.exports = (loggerName) => {
  const childLogger = logger.child({ logger_name: loggerName })
github alphagov / pay-frontend / app / services / charge_param_retriever.js View on Github external
'use strict'

const { PAYMENT_EXTERNAL_ID } = require('@govuk-pay/pay-js-commons').logging.keys
const logger = require('../utils/logger')(__filename)
const { setLoggingField, getLoggingFields } = require('../utils/logging_fields_helper')
const cookie = require('../utils/cookies')

exports.retrieve = req => {
  const chargeId = req.params.chargeId ? req.params.chargeId : req.body.chargeId
  setLoggingField(req, PAYMENT_EXTERNAL_ID, chargeId)

  if (!chargeId) {
    logger.error('ChargeId was not found in request', getLoggingFields(req))
    return false
  } else if (!cookie.getSessionCookieName() || !cookie.isSessionPresent(req)) {
    logger.info('Session cookie is not present', {
      ...getLoggingFields(req),
      referrer: req.get('Referrer'),
      url: req.originalUrl,
github alphagov / pay-selfservice / app / middleware / logging_middleware.js View on Github external
const morgan = require('morgan')
const logger = require('../utils/logger')(__filename)
const { CORRELATION_HEADER } = require('../utils/correlation_header')
const { format } = require('@govuk-pay/pay-js-commons').logging.requestLogFormat(CORRELATION_HEADER)

module.exports = function () {
  return morgan(format, {
    stream: {
      write: message => {
        logger.info('Request received', JSON.parse(message))
      }
    }
  })
}