Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Created September 17, 2019 03:27
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 mariocesar/1cacddce4265bc83e6a9e6e4b9ee8a8f to your computer and use it in GitHub Desktop.
Save mariocesar/1cacddce4265bc83e6a9e6e4b9ee8a8f to your computer and use it in GitHub Desktop.
Output all scripts output as valid json lines / Bash function to output stdout lines as json formatted lines / Useful for logging in AWS ECS to CloudWatch logs
#!/usr/bin/env bash
set -eo pipefail
function message() {
python -c '
import sys
import os
import json
import datetime
for line in sys.stdin:
json.dump({
"date": datetime.datetime.now().isoformat(),
"msg": line,
"name": "logger",
}, sys.stdout)
sys.stdout.write("\n")
sys.stdout.flush()
'
}
ls -al | messsage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment