While I do not agree with _every_ style change, this will force Dokku to have consistent formatting across all shell scripts, which is arguably a Good Thing™. The command used to reprocess everything is: ```shell shfmt -l -bn -ci -i 2 -w . ```
83 lines
2.3 KiB
Bash
Executable File
83 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/logs/internal-functions"
|
|
|
|
logs_default_cmd() {
|
|
declare desc="display recent log output"
|
|
local cmd="logs"
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
local APP="$2"
|
|
verify_app_name "$2"
|
|
local APP_ROOT="$DOKKU_ROOT/$APP"
|
|
local COLORS=(36 33 32 35 31)
|
|
|
|
! (is_deployed "$APP") && dokku_log_fail "App $APP has not been deployed"
|
|
|
|
shift 2
|
|
local TEMP=$(getopt -o htqn:p: --long help,tail,quiet,num:,ps: -n 'dokku logs' -- "$@")
|
|
local EXIT_CODE="$?"
|
|
if [[ "$EXIT_CODE" != 0 ]]; then
|
|
fn-logs-usage >&2
|
|
exit 1
|
|
fi
|
|
eval set -- "$TEMP"
|
|
|
|
local DOKKU_LOGS_LINE_NUMBERS="100"
|
|
while true; do
|
|
case "$1" in
|
|
-t | --tail)
|
|
local DOKKU_LOGS_ARGS+="--follow "
|
|
shift
|
|
;;
|
|
-n | --num)
|
|
local DOKKU_LOGS_LINE_NUMBERS="$2"
|
|
shift 2
|
|
;;
|
|
-p | --ps)
|
|
local DOKKU_LOGS_ONLY_PROCESS="$2"
|
|
shift 2
|
|
;;
|
|
-q | --quiet)
|
|
local DOKKU_LOGS_NO_PRETTY_PRINT="true"
|
|
shift
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
*) dokku_log_fail "Internal error" ;;
|
|
esac
|
|
done
|
|
|
|
if [[ -n $DOKKU_LOGS_ONLY_PROCESS ]]; then
|
|
local CONTAINERS=("$APP_ROOT/CONTAINER.$DOKKU_LOGS_ONLY_PROCESS".*)
|
|
else
|
|
local CONTAINERS=("$APP_ROOT"/CONTAINER.*)
|
|
fi
|
|
[[ -z $(stat -t "${CONTAINERS[0]}" 2>/dev/null) ]] && exit 0
|
|
|
|
local DOKKU_LOGS_ARGS+="--tail $DOKKU_LOGS_LINE_NUMBERS"
|
|
((MAX_INDEX = ${#CONTAINERS[*]} - 1)) || true
|
|
for i in ${!CONTAINERS[*]}; do
|
|
local DYNO=$(echo "${CONTAINERS[i]}" | sed -r 's/.*CONTAINER\.(.*)/\1/')
|
|
local CID=$(<"${CONTAINERS[i]}")
|
|
local COLOR=${COLORS[i % ${#COLORS[*]}]}
|
|
if [[ $DOKKU_LOGS_NO_PRETTY_PRINT == "true" ]]; then
|
|
local DOKKU_LOGS_CMD+="(docker logs $DOKKU_LOGS_ARGS $CID 2>&1)"
|
|
else
|
|
local DOKKU_LOGS_PRETTY_PRINT_CMD="sed -r 's/^([^Z]+Z )/\x1b[${COLOR}m\1app[$DYNO]:\x1b[0m /gm'"
|
|
local DOKKU_LOGS_CMD+="(docker logs -t $DOKKU_LOGS_ARGS $CID 2>&1 | $DOKKU_LOGS_PRETTY_PRINT_CMD)"
|
|
fi
|
|
if [[ $i != "$MAX_INDEX" ]]; then
|
|
local DOKKU_LOGS_CMD+="& "
|
|
else
|
|
local DOKKU_LOGS_CMD+="; "
|
|
fi
|
|
done
|
|
bash -c "($DOKKU_LOGS_CMD)"
|
|
}
|
|
|
|
logs_default_cmd "$@"
|