Skip to content

Instantly share code, notes, and snippets.

@deptno
Last active May 25, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deptno/df8093be6022d3e1fd208b711598e73e to your computer and use it in GitHub Desktop.
Save deptno/df8093be6022d3e1fd208b711598e73e to your computer and use it in GitHub Desktop.
aws-cwlog cloudwatch log transform oneline format
// aws-cwlog trnasform script <https://www.npmjs.com/package/aws-cwlog>
// CloudWatch Log to oneline format eg."2018-05-25T04:41:58 log message"
map(
pipe(
dissoc('ingestionTime'),
over(
lensProp('timestamp'),
pipe(
x => new Date(x).toISOString(),
slice(0, -5),
)
),
over(
lensProp('message'),
pipe(
tryCatch(JSON.parse, identity),
)
),
x => `${x.timestamp} ${pipe(prop('msg'), JSON.stringify)(x.message)}`
),
)
@deptno
Copy link
Author

deptno commented May 25, 2018

map(x => [
  new Date(x.timestamp).toISOString().slice(0, -5),
  JSON.parse(x.message).msg
].join(' '))

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