src/index.js
/**
 * Translates a CloudWatch message into a format appropriate for submitting to the Scalyr uploadLogs API endpoint.
 * Note that the calling function will unpack some of these values into URL params.
 *
 * @param {Object} cloudWatchMessage   Incoming CloudWatch message.
 * @returns {Object}          Outgoing Scalyr message.
 */
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr uploadLogs API endpoint.
Note that the calling function will unpack some of these values into URL params.


Translates a CloudWatch message into a format appropriate for submitting to the Scalyr uploadLogs API endpoint . Note that the calling function will unpack some of these values into URL params .
function transformToUploadLogsMessage(cloudWatchMessage) {
  const serverHost = (defaultServerHost || `cloudwatch-${cloudWatchMessage.owner}`);
  const logfile = (userLogFile || cloudWatchMessage.logGroup);
  return {
    'token': encodeURIComponent(decryptedScalyrApiKey),
    'host': encodeURIComponent(serverHost),
    'logfile': encodeURIComponent(logfile),
    'logStream': encodeURIComponent(cloudWatchMessage.logStream),
    'body': cloudWatchMessage.logEvents.map((cloudWatchEvent) => {
      if (cloudWatchEvent.message.endsWith('\n')) {
        return cloudWatchEvent.message.substr(0, cloudWatchEvent.message.length - 1);
      }
      return cloudWatchEvent.message;
    }).join('\n')
  };
}
function transformToUploadLogsMessage ( cloudWatchMessage ) { const serverHost = ( defaultServerHost || ` ${ cloudWatchMessage . owner } ` ) ; const logfile = ( userLogFile || cloudWatchMessage . logGroup ) ; return { 'token' : encodeURIComponent ( decryptedScalyrApiKey ) , 'host' : encodeURIComponent ( serverHost ) , 'logfile' : encodeURIComponent ( logfile ) , 'logStream' : encodeURIComponent ( cloudWatchMessage . logStream ) , 'body' : cloudWatchMessage . logEvents . map ( ( cloudWatchEvent ) => { if ( cloudWatchEvent . message . endsWith ( '\n' ) ) { return cloudWatchEvent . message . substr ( 0 , cloudWatchEvent . message . length - 1 ) ; } return cloudWatchEvent . message ; } ) . join ( '\n' ) } ; }
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr uploadLogs API endpoint.
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr uploadLogs API endpoint .