MT#9557 Provide timestamps in console output

Change-Id: I5be915fa876014cbb9c792b03be325d6595daac9
changes/07/1907/7
Michael Prokop 11 years ago
parent e35944e2b5
commit 2deea0fb39

@ -26,4 +26,6 @@ SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
# timestamp format for console output
TIME_FORMAT="+%F %T"
## END OF FILE #################################################################

@ -2,32 +2,49 @@
# Purpose: helper functions for ngcpcfg
################################################################################
# console output including timestamps {{{
timestamp_replacementchars='' # unset by default
console_output() {
if [ -z "${TIME_FORMAT:-}" ] ; then
printf -- "$*"
return 0
fi
local timestamp="$(date "$TIME_FORMAT")"
# indent depending on number of characters in date output
timestamp_replacementchars="$(printf -- "%s: " "$timestamp" | sed 's/./ /g')"
printf -- "$timestamp: $*"
}
# }}}
## logging functions {{{
log_info() {
logger -t ngcpcfg -- "$*"
echo "$*"
console_output "$*\n"
}
# info without ending newline
log_info_n() {
logger -t ngcpcfg -- "$*"
printf -- "$*"
console_output "$*"
}
log_warn() {
logger -t ngcpcfg -- "Warning: $*"
echo "Warning: $*"
console_output "Warning: $*\n"
}
log_error() {
logger -t ngcpcfg -- "Error: $*"
echo "Error: $*" >&2
console_output "Error: $*\n" >&2
}
log_debug() {
if [ -n "${DEBUG:-}" ] ; then
logger -t ngcpcfg -- "Debug: $*"
echo ; echo "DEBUG: $*" ; echo # newlines to avoid messup with cmdline output
console_output "DEBUG: $*\n"
fi
}
## }}}
@ -38,14 +55,14 @@ if [ -r ngcpcfg-testsuite.cfg ] ; then
. ngcpcfg-testsuite.cfg
else
if [ -r /etc/ngcp-config/ngcpcfg.cfg ] ; then
log_debug "sourcing configuration file /etc/ngcp-config/ngcpcfg.cfg"
. /etc/ngcp-config/ngcpcfg.cfg
log_debug "sourced configuration file /etc/ngcp-config/ngcpcfg.cfg"
if [ -d /etc/ngcp-config/ngcpcfg.d ] ; then
for file in /etc/ngcp-config/ngcpcfg.d/*.cfg ; do
if test -r $file ; then
log_debug "sourcing configuration file $file"
. $file
log_debug "sourced configuration file $file"
fi
done
fi

@ -4,6 +4,7 @@
set -e
set -u
set -o pipefail
if ! [ -r /usr/share/ngcp-ngcpcfg/functions/main ] ; then
printf "Error: /usr/share/ngcp-ngcpcfg/functions/main could not be read. Exiting.\n" >&2
@ -19,9 +20,11 @@ cd "$NGCPCTL_MAIN"
if [ -z "${NO_DB_SYNC:-}" ] ; then
if [ -f "${RTP_INTERFACES_CONFIG}" ] ; then
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" || true
log_info "Executing sync-db: "
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" | sed "s/^/$timestamp_replacementchars/" || true
else
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" || true
log_info "Executing sync-db: "
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" | sed "s/^/$timestamp_replacementchars/" || true
fi
else
log_debug "no-db-sync: skipping 'sync-db'"
@ -67,7 +70,7 @@ log_debug "/usr/share/ngcp-ngcpcfg/scripts/etckeeper"
if [ -z "${NO_DB_SYNC:-}" ] ; then
log_info "Synchronizing data from ${CONSTANTS_CONFIG}"
ngcp-sync-constants >/dev/null
ngcp-sync-constants >/dev/null | sed "s/^/$timestamp_replacementchars/"
else
log_debug "no-db-sync: skipping 'ngcp-sync-constants'"
fi

@ -4,37 +4,55 @@
set -e
set -u
set -o pipefail
# helper functions {{{
# sadly we can't source ${FUNCTIONS}/main as we are missing a bunch of
# configuration files that are supposed to be available, therefore
# provide the main functions we need for successfull execution of the
# decrypt function
timestamp_replacementchars='' # unset by default
console_output() {
if [ -z "${TIME_FORMAT:-}" ] ; then
printf -- "$*"
return 0
fi
local timestamp="$(date "$TIME_FORMAT")"
# indent depending on number of characters in date output
timestamp_replacementchars="$(printf -- "%s: " "$timestamp" | sed 's/./ /g')"
printf -- "$timestamp: $*"
}
log_info() {
logger -t ngcpcfg -- "$*"
echo "$*"
console_output "$*\n"
}
# info without ending newline
log_info_n() {
logger -t ngcpcfg -- "$*"
printf -- "$*"
}
log_debug() {
if [ -n "${DEBUG:-}" ] ; then
logger -t ngcpcfg -- "Debug: $*"
echo ; echo "DEBUG: $*" ; echo # newlines to avoid messup with cmdline output
fi
console_output "$*"
}
log_warn() {
logger -t ngcpcfg -- "Warning: $*"
echo "Warning: $*"
console_output "Warning: $*\n"
}
log_error() {
logger -t ngcpcfg -- "Error: $*"
echo "Error: $*" >&2
console_output "Error: $*\n" >&2
}
log_debug() {
if [ -n "${DEBUG:-}" ] ; then
logger -t ngcpcfg -- "Debug: $*"
console_output "DEBUG: $*\n"
fi
}
# }}}
@ -76,7 +94,7 @@ else
log_info "Shared storage exists already, ignoring request to (re)install it."
else
log_info "Copying git repository to shared storage."
git clone --bare /etc/ngcp-config /mnt/glusterfs/ngcpcfg-share
git clone --bare /etc/ngcp-config /mnt/glusterfs/ngcpcfg-share | sed "s/^/$timestamp_replacementchars/"
fi
fi

@ -4,6 +4,7 @@
set -e
set -u
set -o pipefail
if ! [ -r /usr/share/ngcp-ngcpcfg/functions/main ] ; then
printf "Error: /usr/share/ngcp-ngcpcfg/functions/main could not be read. Exiting.\n" >&2
@ -23,14 +24,14 @@ git diff $*
log_debug "git status --porcelain | awk '/^\?\? / {print \$2}'"
if git status --porcelain | awk '/^\?\? / {print $2}' | grep -q . ; then
log_info "* New but not yet registered files inside ${NGCPCTL_MAIN}:"
git status --porcelain | awk '/^\?\? / {print $2}'
git status --porcelain | awk '/^\?\? / {print $2}' | sed "s/^/$timestamp_replacementchars/"
fi
# deleted files
log_debug "git status --porcelain | awk '/^D / {print \$2}'"
if git status --porcelain | awk '/^D / {print $2}' | grep -q . ; then
log_info "* Removed but not yet unregistered files inside ${NGCPCTL_MAIN}:"
git status --porcelain | awk '/^D / {print $2}'
git status --porcelain | awk '/^D / {print $2}' | sed "s/^/$timestamp_replacementchars/"
fi
## END OF FILE #################################################################

@ -4,6 +4,7 @@
set -e
set -u
set -o pipefail
if ! [ -r /usr/share/ngcp-ngcpcfg/functions/main ] ; then
printf "Error: /usr/share/ngcp-ngcpcfg/functions/main could not be read. Exiting.\n" >&2
@ -35,7 +36,7 @@ if git status | grep -q 'working directory clean' ; then
log_info "OK: nothing to commit."
else
log_debug 'etckeeper commit "ngcpcfg apply on $(date)"'
etckeeper commit "ngcpcfg apply on $(date)"
etckeeper commit "ngcpcfg apply on $(date)" | sed "s/^/$timestamp_replacementchars/"
fi
## END OF FILE #################################################################

@ -4,6 +4,7 @@
set -e
set -u
set -o pipefail
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
@ -61,13 +62,13 @@ check_local_state() {
if git diff-index --name-only HEAD | grep -q . ; then
log_info "ACTION_NEEDED: configuration files have been modified:"
log_debug "git diff-index --name-only HEAD | sed \"s;^;${NGCPCTL_MAIN}/;\""
git diff-index --name-only HEAD | sed "s;^;${NGCPCTL_MAIN}/;"
git diff-index --name-only HEAD | sed "s;^;${NGCPCTL_MAIN}/;" | sed "s/^/$timestamp_replacementchars/"
fi
if git ls-files --other --exclude-standard | grep -q . ; then
log_info "ACTION_NEEDED: configuration files have been added:"
log_debug "git ls-files --other --exclude-standard | sed \"s;^;${NGCPCTL_MAIN}/;\""
git ls-files --other --exclude-standard | sed "s;^;${NGCPCTL_MAIN}/;"
git ls-files --other --exclude-standard | sed "s;^;${NGCPCTL_MAIN}/;" | sed "s/^/$timestamp_replacementchars/"
fi
log_info "-> execute 'ngcpcfg build' and 'ngcpcfg commit'"

Loading…
Cancel
Save