Commit d11dc868 authored by Emeric Verschuur's avatar Emeric Verschuur

Add print_log function

parent f3f7d67f
......@@ -15,6 +15,33 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# display a message
print_log() {
local level=$1;
shift || print_log C "Usage print_log <level> message"
case "${level,,}" in
c|critical)
>&2 printf "\e[91m[CRIT] %s\e[0m\n" "$@"
exit 1
;;
e|error)
>&2 printf "\e[91m[ERRO] %s\e[0m\n" "$@"
;;
w|warning)
>&2 printf "\e[93m[WARN] %s\e[0m\n" "$@"
;;
n|note)
printf "[NOTE] %s\n" "$@"
;;
i|info)
printf "\e[92m[INFO] %s\e[0m\n" "$@"
;;
*)
print_log C "Invalid log level: $level"
;;
esac
}
# Print an error message and exit with error status 1
print_critical() {
>&2 printf "\e[91m[CRIT] %s\e[0m\n" "$@"
......@@ -386,6 +413,7 @@ BASHOPTS_FILE_PATH=${BASHOPTS_FILE_PATH:-"$CITBX_ABS_DIR/3rdparty/bashopts.sh"}
if [ ! -f "$BASHOPTS_FILE_PATH" ]; then
print_critical "Missing requered file $BASHOPTS_FILE_PATH [\$BASHOPTS_FILE_PATH]"
fi
bashopts_log_handler="print_log"
. $BASHOPTS_FILE_PATH
# Enable backtrace dusplay on error
trap 'bashopts_exit_handle' ERR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment