1
0
Fork 0

consolidate autorun logs

This commit is contained in:
Luca Bilke 2024-02-09 16:30:50 +01:00
parent 4e098d042e
commit 329b10845f

View file

@ -4,26 +4,18 @@ trap 'kill $pids $(pidof xcape) 1>/dev/null 2>&1' 2 15 EXIT
LOGFILE="${LOGFILE:-${HOME}/.local/log/session-$(date -I).log}"
infolog() {
log() {
while IFS= read -r line; do
printf "%b" "[$(date +%X)][INF][$1]\t$line\n" >>"${LOGFILE}"
done
}
errorlog() {
while IFS= read -r line; do
printf "%b" "[$(date +%X)][ERR][$1]\t$line\n" >>"${LOGFILE}"
printf "%b" "[$(date +%X)][$1]\t$line\n" >>"${LOGFILE}"
done
}
start() {
stdout="${XDG_RUNTIME_DIR:-/tmp}/${1}-stdout"
stderr="${XDG_RUNTIME_DIR:-/tmp}/${1}-stderr"
[ -p "$stdout" ] || mkfifo "$stdout"
[ -p "$stderr" ] || mkfifo "$stderr"
cat <"$stdout" | infolog "$1" &
cat <"$stderr" | errorlog "$1" &
pidof -sx "$1" || "./$1" >"$stdout" 2>"$stderr" &
logp="${XDG_RUNTIME_DIR:-/tmp}/${1}"
[ -p "$logp" ] || mkfifo "$logp"
cat <"$logp" | log "$1" &
pidof -sx "$1" || "./$1" >"$logp" 2>&1 &
# pidof -sx "$1" || "./$1" 2>&1 | log "$1" &
}
cd "$HOME/.local/libexec/dwm/autorun.d" || exit 1