function reformatLogLine({ logLine, msg, agent, level, logger }) {
  const metadata = agent.getLinkingMetadata(true)

  const agentMeta = Object.assign({}, { timestamp: Date.now() }, metadata)
  // eslint-disable-next-line eqeqeq
  if (msg != undefined) {
    // The spec lists `message` as "MUST" under the required column, but then
    // details that it "MUST be omitted" if the value is "empty". Additionally,
    // if someone has logged only a merging object, and that object contains a
    // message key, we do not want to overwrite their value. See issue 2595.
    agentMeta.message = msg
  }

  /**
   * A function that gets executed in `_toPayloadSync` of log aggregator.
   * This will parse the serialized log line and then add the relevant NR
   * context metadata and rename the time/msg keys to timestamp/message
   */
  return function formatLogLine() {
    let formattedLog
    try {
      formattedLog = JSON.parse(logLine)
    } catch (err) {
      logger.error('Failed to parse log line as json: %s', err.message)
      return
    }

    if (formattedLog.err) {
      reformatError(formattedLog)
    }
    Object.assign(formattedLog, agentMeta)
    formattedLog.level = level
    delete formattedLog.time
    delete formattedLog.msg
    return formattedLog
  }
}
reformats error and assigns NR context data
to log line

@param {object} params to function
@param {object} params.logLine log line
@param {string} params.msg message of log line
@param {object} params.agent instance of agent
@param {string} params.level log level
@param {object} params.logger instance of agent logger
@returns {function} wrapped log formatter function