# shellcheck shell=dash
# Section: log recent

# TODO: Using stack to show all the recent log.

# x log recent push [--fail] [--desc <description>] <logpath>
# x log recent pop
# x log recent gc

# x log app begin --print error --dump all <appname> <description> <filepath>
# redirect the log to the filepath
# all log go to the filepath --dump debug(default)
# hiding all of the log --print none(default)
# x log app end [--fail]

___x_cmd_log_recent(){
    if [ "$#" -eq 0 ]; then
        ___x_cmd_log_recent less
        return 0
    fi

    local op="$1"; shift
    case "$op" in
        set)
                ___X_CMD_LOG_RECENT_PATH="$1"
                ;;
        path)
                [ -n "${___X_CMD_LOG_RECENT_PATH}" ] || {
                    log:warn "Recent log path unset."
                    return 1
                }
                printf "%s\n" "${___X_CMD_LOG_RECENT_PATH}"
                ;;
        cat)
                [ -n "${___X_CMD_LOG_RECENT_PATH}" ] || {
                    log:warn "Recent log path unset."
                    return 1
                }
                "$op" "${___X_CMD_LOG_RECENT_PATH}"
                ;;
        less)
                [ -n "${___X_CMD_LOG_RECENT_PATH}" ] || {
                    log:warn "Recent log path unset."
                    return 1
                }
                printf "%s\n" "${___X_CMD_LOG_RECENT_PATH}"
                ;;
    esac
}

## EndSection
