Simplify logging style

Signed-off-by: tytydraco <tylernij@gmail.com>
latency
tytydraco 4 years ago
parent c10aafc1f9
commit 540070edc2

@ -1,36 +1,6 @@
#!/usr/bin/env bash
# Written by Draco (tytydraco @ GitHub)
# Log in red
err() {
if [[ -n "$SIMPLE_LOGGING" ]]
then
echo "ERROR $*"
else
echo -e " \e[91m*\e[39m $*"
fi
}
# Log in orange
warn() {
if [[ -n "$SIMPLE_LOGGING" ]]
then
echo "WARNING $*"
else
echo -e " \e[93m*\e[39m $*"
fi
}
# Log in white and continue (unnecessary)
dbg() {
if [[ -n "$SIMPLE_LOGGING" ]]
then
echo "DEBUG $*"
else
echo -e " \e[92m*\e[39m $*"
fi
}
# Safely write value to file
write() {
# Bail out if file does not exist
@ -40,61 +10,29 @@ write() {
local curval
curval="$(cat "$1" 2> /dev/null)"
# Bail out if value is already set
if [[ "$curval" == "$2" ]]
then
warn "$1: $curval → $2"
return 0
fi
# Make file writable
chmod +w "$1" 2> /dev/null
# Write the new value
if ! echo "$2" > "$1" 2> /dev/null
then
err "$1: $curval → $2"
echo "Failed: $1: $curval → $2"
return 1
fi
dbg "$1: $curval → $2"
echo "$1: $curval → $2"
}
usage() {
echo -n "Usage: $(basename "$0") [OPTIONS]
Options:
-p Parsable logging
-h Show usage
"
}
while getopts ":ph" opt; do
case $opt in
p)
SIMPLE_LOGGING=1
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
# Check for root permissions
if [[ "$(id -u)" -ne 0 ]]
then
err "No root permissions. Exiting."
echo "No root permissions. Exiting."
exit 1
fi
# Log the date and time
dbg "Time of execution: $(date)"
echo "Time of execution: $(date)"
# Kernel
write /proc/sys/kernel/perf_cpu_time_max_percent 5

Loading…
Cancel
Save