Blame subr/rtl_log.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz 2b85d0
# set +o errexit -o noglob is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_FAIL_COLOUR:=91};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_INFO_COLOUR:=93};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_INF2_COLOUR:=33};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_SUCC_COLOUR:=92};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_SUC2_COLOUR:=32};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_VNFO_COLOUR:=96};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_VUCC_COLOUR:=90};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_VVFO_COLOUR:=96};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_VVVO_COLOUR:=96};
Lucio Andrés Illanes Albornoz ae3ff0
: ${DEFAULT_LOG_MSG_VVVV_COLOUR:=96};
Lucio Andrés Illanes Albornoz ae3ff0
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
exp_rtl_log_printf() {
Lucio Andrés Illanes Albornoz 907bd3
	local _attrs="${1}" _msg=""; shift; _msg="$(printf "${@}")";
Lucio Andrés Illanes Albornoz 2b85d0
	if [ "${BUILD_IS_PARENT:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz 2b85d0
	&& [ -n "${DEFAULT_BUILD_LOG_FNAME}" ]\
Lucio Andrés Illanes Albornoz 2b85d0
	&& [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		printf "%s\n" "${_msg}" >> "${DEFAULT_BUILD_LOG_FNAME}";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
};
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
Lucio Andrés Illanes Albornoz c6d6e0
rtl_log_env_vars() {
Lucio Andrés Illanes Albornoz 907bd3
	local _nvar=1 _arg="" _arg_len_max=0;
Lucio Andrés Illanes Albornoz c6d6e0
	rtl_log_msg info "Variables for this ${1:-build}:"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${_nvar} -le ${#} ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_arg="$(eval echo \${${_nvar}})";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_arg="${_arg%%=*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		if [ ${#_arg} -gt ${_arg_len_max} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			_arg_len_max=${#_arg};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		fi; : $((_nvar+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz c6d6e0
		rtl_log_msg info "$(printf			\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			"%${_arg_len_max}.${_arg_len_max}s=%s"	\
Lucio Andrés Illanes Albornoz c6d6e0
			"${1%%=*}" "$(rtl_get_var_unsafe ${1#*=})")";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz c6d6e0
rtl_log_set_vnfo_lvl() {
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	EXP_RTL_LOG_VNFO_LVL="${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz c6d6e0
rtl_log_msg() {
Lucio Andrés Illanes Albornoz 584601
	local _lvl="${1}" _lvl_uc="" _attr=""; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	if [ "${_lvl}" = vnfo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 5c1ec1
	|| [ "${_lvl}" = vucc ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	&& [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	elif [ "${_lvl}" = vvfo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	&& [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	elif [ "${_lvl}" = vvvo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	&& [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 3 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
		return;
Lucio Andrés Illanes Albornoz f0dfe1
	elif [ "${_lvl}" = vvvv ]\
Lucio Andrés Illanes Albornoz f0dfe1
	&& [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 4 ]; then
Lucio Andrés Illanes Albornoz f0dfe1
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	fi;
Lucio Andrés Illanes Albornoz c6d6e0
	_lvl_uc="$(rtl_toupper "${_lvl%exit}")";
Lucio Andrés Illanes Albornoz c6d6e0
	_attr="$(rtl_get_var_unsafe "DEFAULT_LOG_MSG_${_lvl_uc}_COLOUR")";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	if [ ${#} -gt 1 ]; then
Lucio Andrés Illanes Albornoz c6d6e0
		exp_rtl_log_printf "${_attrs}" "==> %s %s %s" "$(rtl_date)" "${1}" "$*";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	else
Lucio Andrés Illanes Albornoz c6d6e0
		exp_rtl_log_printf "${_attrs}" "==> %s %s" "$(rtl_date)" "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	if [ ${_lvl} = failexit ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	else
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# vim:filetype=sh