Improve logging

logging is treated as other hooks regarding verbose and dry-run modes
This commit is contained in:
Jérémy Lecour 2019-03-15 22:53:08 +01:00
parent 72f7dc1159
commit c47ebee7c0

View file

@ -130,31 +130,23 @@ get_repository_status() {
unset GIT_DIR GIT_WORK_TREE
}
print_summary() {
BLOB=$(cat <<END
Host : $HOSTNAME_TEXT
User : $USER
IP : $IP
Begin : $BEGIN_DATE
End : $END_DATE
Message : $MESSAGE
END
)
printf "%s\n\n" "${BLOB}"
print_log() {
printf "*********** %s ***************\n" "$(get_now)"
print_session_data
printf "Hooks : commit=%s db=%s mail=%s\n"\
"${HOOK_COMMIT}" "${HOOK_DB}" "${HOOK_MAIL}"
if [ "${HOOK_MAIL}" = "1" ]; then
printf "Mailto : %s\n" "${EVOMAINTMAIL}"
fi
}
print_options() {
cat <<END
********** Options ****************
MESSAGE: ${MESSAGE}
HOOK_COMMIT: ${HOOK_COMMIT}
HOOK_DB: ${HOOK_DB}
HOOK_MAIL: ${HOOK_MAIL}
DRY_RUN: ${DRY_RUN}
AUTO: ${AUTO}
***********************************
END
print_session_data() {
printf "Host : %s\n" "${HOSTNAME_TEXT}"
printf "User : %s\n" "${USER}"
printf "IP : %s\n" "${IP}"
printf "Begin : %s\n" "${BEGIN_DATE}"
printf "End : %s\n" "${END_DATE}"
printf "Message : %s\n" "${MESSAGE}"
}
hook_commit() {
@ -234,7 +226,12 @@ hook_mail() {
}
hook_log() {
printf "*********** %s ***************\n%s\n" "$(get_now)" "${BLOB}" >> "${LOGFILE}"
if [ "${VERBOSE}" = "1" ]; then
print_log
fi
if [ "${DRY_RUN}" != "1" ]; then
print_log >> "${LOGFILE}"
fi
}
# load configuration if present.
@ -342,9 +339,6 @@ while :; do
shift
done
if [ "${VERBOSE}" = "1" ]; then
print_options
fi
# Treat unset variables as an error when substituting.
# Only after this line, because some config variables might be missing.
@ -408,16 +402,11 @@ if [ -z "${MESSAGE}" ]; then
exit 1
fi
print_summary
# Log hook
if [ "${DRY_RUN}" != "1" ]; then
hook_log
fi
print_session_data
if [ "${INTERACTIVE}" = "1" ] && [ "${AUTO}" = "0" ]; then
if [ "${HOOK_COMMIT}" = "1" ] || [ "${HOOK_MAIL}" = "1" ] || [ "${HOOK_DB}" = "1" ]; then
printf "Actions to execute:\n"
printf "\nActions to execute:\n"
if [ "${HOOK_COMMIT}" = "1" ]; then
printf "* commit changes in repositories\n"
fi
@ -562,6 +551,9 @@ if [ "${INTERACTIVE}" = "1" ] && [ "${AUTO}" = "0" ]; then
done
fi
# Log hook
hook_log
if [ "${INTERACTIVE}" = "0" ] || [ "${AUTO}" = "1" ]; then
if [ "${HOOK_COMMIT}" = "1" ]; then
hook_commit