feat: allow tailing a specific number of log lines

This commit is contained in:
Jose Diaz-Gonzalez
2021-10-26 22:27:14 -04:00
parent 2f33b6deb3
commit 1c7d121a07
4 changed files with 20 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ postgres:link <service> <app> [--link-flags...] # link the postgres service t
postgres:linked <service> <app> # check if the postgres service is linked to an app
postgres:links <service> # list all apps linked to the postgres service
postgres:list # list all postgres services
postgres:logs <service> [-t|--tail] # print the most recent log(s) for this service
postgres:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log(s) for this service
postgres:promote <service> <app> # promote service <service> as DATABASE_URL in <app>
postgres:restart <service> # graceful shutdown and restart of the postgres service container
postgres:start <service> # start a previously stopped postgres service
@@ -159,12 +159,12 @@ dokku postgres:list
```shell
# usage
dokku postgres:logs <service> [-t|--tail]
dokku postgres:logs <service> [-t|--tail] <tail-num-optional>
```
flags:
- `-t|--tail`: do not stop when end of the logs are reached and wait for additional output
- `-t|--tail [<tail-num>]`: do not stop when end of the logs are reached and wait for additional output
You can tail logs for a particular service:
@@ -178,6 +178,12 @@ By default, logs will not be tailed, but you can do this with the --tail flag:
dokku postgres:logs lollipop --tail
```
The default tail setting is to show all logs, but an initial count can also be specified:
```shell
dokku postgres:logs lollipop --tail 5
```
### link the postgres service to the app
```shell

View File

@@ -578,14 +578,14 @@ service_list() {
service_logs() {
declare desc="display logs for a service"
declare SERVICE="$1" TAIL_FLAG="$2"
declare SERVICE="$1" TAIL_FLAG="$2" TAIL_COUNT="$3"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID=$(cat "$SERVICE_ROOT/ID")
local RE_INTEGER='^[0-9]+$'
DOKKU_LOGS_ARGS="--tail 100"
DOKKU_LOGS_ARGS="--tail $TAIL_COUNT"
if [[ "$TAIL_FLAG" == "-t" ]] || [[ "$TAIL_FLAG" == "--tail" ]]; then
DOKKU_LOGS_ARGS="--follow"
DOKKU_LOGS_ARGS+=" --follow"
fi
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"

View File

@@ -202,6 +202,9 @@ fn-help-subcommand-args() {
elif [[ "$arg" == *_LIST ]]; then
arg=${arg%_*}
args+=" <${arg//_/-}...>"
elif [[ "$arg" == *_OPTIONAL ]]; then
argName="${arg/_OPTIONAL/}"
args+=" [<${argName//_/-}>]"
else
args+=" <${arg//_/-}>"
fi

View File

@@ -10,16 +10,18 @@ service-logs-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:logs lollipop
#E by default, logs will not be tailed, but you can do this with the --tail flag:
#E dokku $PLUGIN_COMMAND_PREFIX:logs lollipop --tail
#E the default tail setting is to show all logs, but an initial count can also be specified
#E dokku $PLUGIN_COMMAND_PREFIX:logs lollipop --tail 5
#A service, service to run command against
#F -t|--tail, do not stop when end of the logs are reached and wait for additional output
#F -t|--tail [<tail-num>], do not stop when end of the logs are reached and wait for additional output
declare desc="print the most recent log(s) for this service"
local cmd="$PLUGIN_COMMAND_PREFIX:logs" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" TAIL_FLAG="$2"
declare SERVICE="$1" TAIL_FLAG="$2" TAIL_NUM_OPTIONAL="${3:-all}"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
verify_service_name "$SERVICE"
service_logs "$SERVICE" "$TAIL_FLAG"
service_logs "$SERVICE" "$TAIL_FLAG" "$TAIL_NUM_OPTIONAL"
}
service-logs-cmd "$@"