Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 0185bc
# set -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 (arab, vxp) a43dbf
exp_rtl_log_printf() {
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	local _attrs="${1}" _msg; shift; _msg="$(printf "${@}")";
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	if [ "${BUILD_IS_PARENT:-0}" -eq 1 ]; 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 (arab, vxp) ec19f0
ex_rtl_log_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _nvar=1 _arg _arg_len_max=0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	ex_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 (arab, vxp) ec19f0
		ex_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 (arab, vxp) ec19f0
			"${1%%=*}" "$(ex_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 (arab, vxp) ec19f0
ex_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 (arab, vxp) ec19f0
ex_rtl_log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
	local _lvl="${1}" _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 (arab, vxp) 32ad21
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	case "${_lvl}" in
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		failexit) _attr="${DEFAULT_LOG_MSG_FAIL_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		fail) _attr="${DEFAULT_LOG_MSG_FAIL_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		info) _attr="${DEFAULT_LOG_MSG_INFO_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		inf2) _attr="${DEFAULT_LOG_MSG_INF2_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		vnfo) _attr="${DEFAULT_LOG_MSG_VNFO_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		vvfo) _attr="${DEFAULT_LOG_MSG_VVFO_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		vvvo) _attr="${DEFAULT_LOG_MSG_VVVO_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		succ) _attr="${DEFAULT_LOG_MSG_SUCC_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		suc2) _attr="${DEFAULT_LOG_MSG_SUC2_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		vucc) _attr="${DEFAULT_LOG_MSG_VUCC_COLOUR}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	if [ ${#} -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		exp_rtl_log_printf "${_attrs}" "==> %s %s %s" "$(ex_rtl_date)" "${1}" "$*";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	else
Lucio Andrés Illanes Albornoz (arab, vxp) a43dbf
		exp_rtl_log_printf "${_attrs}" "==> %s %s" "$(ex_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