Created
September 17, 2019 03:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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