feat: Add log formating ability
This commit is contained in:
parent
d1a5eefb7a
commit
444b6df4da
@ -34,6 +34,9 @@ log() {
|
|||||||
# If no arguments AND '0' descriptor is closed, then 'message' will not be set.
|
# If no arguments AND '0' descriptor is closed, then 'message' will not be set.
|
||||||
[[ "$#" == 0 || -t 0 ]] || message="$(cat <&0)"
|
[[ "$#" == 0 || -t 0 ]] || message="$(cat <&0)"
|
||||||
|
|
||||||
|
# Set log date format
|
||||||
|
[ -n "$log_date_fmt" ] || log_date_fmt='%d/%b/%Y:%H:%M:%S %z'
|
||||||
|
|
||||||
while (( "$#" )); do
|
while (( "$#" )); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-p|--print) print=1; shift;;
|
-p|--print) print=1; shift;;
|
||||||
@ -45,6 +48,6 @@ log() {
|
|||||||
[[ "$print" == 1 ]] && echo "$message"
|
[[ "$print" == 1 ]] && echo "$message"
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
printf '[%s] [%s] %s\n' "$(date +'%d %b %Y %H:%M:%S %z')" "$0" "$line" >> "$log_file"
|
printf '[%s] [%s] %s\n' "$(date +"$log_date_fmt")" "$0" "$line" >> "$log_file"
|
||||||
done <<< "$(sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' <<< "$message")"
|
done <<< "$(sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' <<< "$message")"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user