Add log viewing helper based on svlogtail
This commit is contained in:
parent
d119404ae4
commit
f9bc7405a9
3 changed files with 63 additions and 5 deletions
42
utils/svlogs
Executable file
42
utils/svlogs
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue