Add log viewing helper based on svlogtail

This commit is contained in:
crater2150 2023-08-21 11:33:55 +02:00
parent d119404ae4
commit f9bc7405a9
3 changed files with 63 additions and 5 deletions

View file

@ -3,15 +3,20 @@
Various runit service files for per-user services. May need to be modified to work on your system.
Helper scripts:
- `log`: symlink as the `run` script in your service's log directory to enable logging to `~/.local/log/`
- `setup-supervise.zsh`: run to create symlinks for `supervise` directories, so they are created in $XDG_RUNTIME_DIR
- `new-service`: create a new service, executing the given command line.
- `log`: symlink as the `run` script in your service's log directory to enable
logging to `~/.local/log/`
- `utils/setup-supervise.zsh`: run to create symlinks for `supervise`
directories, so they are created in $XDG_RUNTIME_DIR
- `utils/new-service`: create a new service, executing the given command line.
Accepted options before service name:
- `-l`, `--log`: create a log directory and symlink `log` script
- `-i PROC`, `--import-env PROC`: include import-env script and import environment from process `PROC`
Example
```sh
utils/new-service -l my-daemon --foreground -a -b -c
```
./new-service -l my-daemon --foreground -a -b -c
```
- `utils/svlogs`: like svlogtail for user services. Uses $SVLOGDIRS or
`~/.local/log/` as base dir. ZSH completion file available in
`utils/completions`

11
utils/completion/_svlogs Normal file
View file

@ -0,0 +1,11 @@
#compdef svlogs
local logs=( ${SVLOGDIR:-$HOME/.local/log}/* )
logs=( ${logs:t} )
local arguments=(
'-o[show old logs]'
'--old[show old logs]'
"::logs:(${logs})"
)
_arguments $arguments

42
utils/svlogs Executable file
View 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