Details
-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
Description
In function `setupFilesTomcat_sslCertsClient`, most of the log message identify themselves as being called from `setupFilesTomcat_sslCertsAnchors`, e.g.,
255 echo "grouperContainer; INFO: (librarySetupFilesTomcat.sh-setupFilesTomcat_sslCertsAnchors) chmod u+w $JAVA_HOME/lib/security/cacerts , result=$returnCode" |
It seems like it would be better to take advantage of bash's builtin facilities for reporting locations and define functions to remove much of the noise and potential for copy & paste errors, like this:
#!/bin/bash
|
# libLog.sh
|
__log_output_tag="grouperContainer"
|
|
_log_base() {
|
local level="$1"
|
local message="$2"
|
|
local source="$(basename ${BASH_SOURCE[2]})"
|
|
local origin
|
if [[ -n "${FUNCNAME[2]}" && "${FUNCNAME[2]}" != "main" ]]; then
|
origin="${source}-${FUNCNAME[2]}"
|
else
|
origin="${source}"
|
fi
|
|
printf "${__log_output_tag}; ${level}: (${origin}) ${message}\n"
|
}
|
|
log_info() {
|
_log_base INFO "$*"
|
}
|
|
log_warn() {
|
_log_base WARN "$*"
|
}
|
|
# ... etc for the rest of the logging levels
|
Here's a small demonstration script:
#!/bin/bash
|
|
source /tmp/libLog.sh
|
|
foo() {
|
log_info "Hi foo"
|
}
|
|
bar() {
|
log_info Hi bar
|
foo
|
}
|
|
baz() {
|
log_warn Baz on
|
bar
|
}
|
baz
|
log_info Called from main
|
log_info Called from main through a pipe | tee /tmp/pretend-this-is-a-pipe
|
Abstracting the logging this way would also make it easier to incorporate $ENV and $USERTOKEN and make the format consistent with the formats used everywhere else.