Skip to content

Instantly share code, notes, and snippets.

@hayd
Last active June 27, 2023 12:28
Show Gist options
  • Save hayd/1249bd4f1fa17764fd70dcf2210bf044 to your computer and use it in GitHub Desktop.
Save hayd/1249bd4f1fa17764fd70dcf2210bf044 to your computer and use it in GitHub Desktop.
Modify elastic beanstalk default log output prefix

By default elastic beanstalk logs are prefixed by the date and the ip. This is may not be desired, either because the date is also in the logs or because the timestamp is included in cloudwatch logs metadata.

We can remove it by adding two hooks (both with the same content):

  • .platform/hooks/predeploy/10_logs.sh
  • .platform/confighooks/predeploy/10_logs.sh

Note: You must ensure these are executable before packaing (chmod +x).

#!/bin/sh
# By default logs output to /var/log/web.stdout.log are prefixed.
# We want just the raw logs from the app...
# This updates the rsyslog config (to use the WebTemplate format).
# Also grants read permissions to the log files.

# This file is duplicated here:
# .platform/hooks/predeploy/10_logs.sh
# .platform/confighooks/predeploy/10_logs.sh

set -eu

echo '
# This file is created from Elastic Beanstalk platform hooks.
template(name="WebTemplate" type="string" string="%msg%\n")

if \$programname == "web" then {
  *.=warning;*.=err;*.=crit;*.=alert;*.=emerg; /var/log/web.stderr.log;WebTemplate
  *.=info;*.=notice /var/log/web.stdout.log;WebTemplate
}
' > /etc/rsyslog.d/web.conf

touch /var/log/web.stdout.log
touch /var/log/web.stderr.log
chmod +r /var/log/web.stdout.log
chmod +r /var/log/web.stderr.log

systemctl restart rsyslog.service

This is a modification of yo1dog's serverfault answer.

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