Skip to content

Instantly share code, notes, and snippets.

@FL33TW00D
Created April 23, 2022 20:47
Show Gist options
  • Save FL33TW00D/76e1e0bc66d87b38f2eac35ca61ce695 to your computer and use it in GitHub Desktop.
Save FL33TW00D/76e1e0bc66d87b38f2eac35ca61ce695 to your computer and use it in GitHub Desktop.
Bunyan format logs from Digital Ocean
#!/bin/bash
deployment_id=`doctl apps list | grep -m 1 -Eo '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}' | head -1`
curdate=`gdate +%s`
logs=`doctl apps logs ${deployment_id} --tail 10000 > logs/$PROJECT_NAME-${curdate}.log`
sed -i '' 's/$PROJECT_NAME .*{/{/g' logs/$PROJECT_NAME-${curdate}.log
cat logs/$PROJECT_NAME-${curdate}.log | bunyan
if [ $? -eq 0 ]; then
echo Successfully retrieved and tailed logs for ${deployment_id}
else
echo Failed to tail logs
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment