runit-user-services/utils/svlogs

43 lines
964 B
Plaintext
Raw Normal View History

#!/bin/zsh
# based on svlogtail from socklock-void package
usage () {
cat <<-'EOF'
svlogs [-o] [LOG...] - show svlogd logs conveniently, for user services
Without arguments, show current logs of all services, uniquely.
With arguments, show all logs of mentioned services
Uses $SVLOGDIR as base for log directories if set, defaults to ~/.local/log
Options:
-o, --old Show old logs, too
EOF
}
BASE_LOGDIR=${SVLOGDIR:-$HOME/.local/log}
zparseopts -D -E o=showold -old=showold
if [[ -z $@ ]]; then
cat ${showold:+$BASE_LOGDIR/*/*.[us](N)} $BASE_LOGDIR/*/current | sort -u
tail -Fq -n0 $BASE_LOGDIR/*/current | uniq
else
old=()
cur=()
for log; do
case "$log" in
-*) usage; exit 1;;
esac
if [[ -d $BASE_LOGDIR/$log ]]; then
old+=( $BASE_LOGDIR/$log/*.[us](N) )
cur+=( $BASE_LOGDIR/$log/current )
else
echo "no logs for $log" 1>&2
exit 1
fi
done
cat ${showold:+$old} $cur | sort
tail -Fq -n0 $cur
fi