feat: allow tailing a specific number of log lines

This commit is contained in:
Jose Diaz-Gonzalez
2021-10-26 22:27:13 -04:00
parent c44089527f
commit 529d339ee5
4 changed files with 20 additions and 9 deletions

View File

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

View File

@@ -578,14 +578,14 @@ service_list() {
service_logs() { service_logs() {
declare desc="display logs for a service" 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 SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID=$(cat "$SERVICE_ROOT/ID") local ID=$(cat "$SERVICE_ROOT/ID")
local RE_INTEGER='^[0-9]+$' local RE_INTEGER='^[0-9]+$'
DOKKU_LOGS_ARGS="--tail 100" DOKKU_LOGS_ARGS="--tail $TAIL_COUNT"
if [[ "$TAIL_FLAG" == "-t" ]] || [[ "$TAIL_FLAG" == "--tail" ]]; then if [[ "$TAIL_FLAG" == "-t" ]] || [[ "$TAIL_FLAG" == "--tail" ]]; then
DOKKU_LOGS_ARGS="--follow" DOKKU_LOGS_ARGS+=" --follow"
fi fi
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist" 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 elif [[ "$arg" == *_LIST ]]; then
arg=${arg%_*} arg=${arg%_*}
args+=" <${arg//_/-}...>" args+=" <${arg//_/-}...>"
elif [[ "$arg" == *_OPTIONAL ]]; then
argName="${arg/_OPTIONAL/}"
args+=" [<${argName//_/-}>]"
else else
args+=" <${arg//_/-}>" args+=" <${arg//_/-}>"
fi fi

View File

@@ -10,16 +10,18 @@ service-logs-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:logs lollipop #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 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 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 #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" declare desc="print the most recent log(s) for this service"
local cmd="$PLUGIN_COMMAND_PREFIX:logs" argv=("$@") local cmd="$PLUGIN_COMMAND_PREFIX:logs" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1 [[ ${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" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
verify_service_name "$SERVICE" verify_service_name "$SERVICE"
service_logs "$SERVICE" "$TAIL_FLAG" service_logs "$SERVICE" "$TAIL_FLAG" "$TAIL_NUM_OPTIONAL"
} }
service-logs-cmd "$@" service-logs-cmd "$@"