Extra space to align log output

This commit is contained in:
Søren Theilgaard
2022-02-04 09:02:56 +01:00
parent 516f05a4cb
commit ee9861c0f5

View File

@@ -97,14 +97,21 @@ printlog(){
curl -s -X POST https://http-intake.logs.datadoghq.com/v1/input -H "Content-Type: text/plain" -H "DD-API-KEY: $datadogAPI" -d "${log_priority} : $mdmURL : Installomator-${label} : ${VERSIONDATE//-/} : $SESSION : ${logmessage}" > /dev/null curl -s -X POST https://http-intake.logs.datadoghq.com/v1/input -H "Content-Type: text/plain" -H "DD-API-KEY: $datadogAPI" -d "${log_priority} : $mdmURL : Installomator-${label} : ${VERSIONDATE//-/} : $SESSION : ${logmessage}" > /dev/null
done <<< "$log_message" done <<< "$log_message"
fi fi
# Extra spaces
space_char=""
if [[ ${#log_priority} -eq 3 ]]; then
space_char=" "
elif [[ ${#log_priority} -eq 4 ]]; then
space_char=" "
fi
# If our logging level is greaterthan or equal to our set level then output locally. # If our logging level is greaterthan or equal to our set level then output locally.
if [[ ${levels[$log_priority]} -ge ${levels[$LOGGING]} ]]; then if [[ ${levels[$log_priority]} -ge ${levels[$LOGGING]} ]]; then
while IFS= read -r logmessage; do while IFS= read -r logmessage; do
if [[ "$(whoami)" == "root" ]]; then if [[ "$(whoami)" == "root" ]]; then
echo "$timestamp" : "${log_priority} : $label : ${logmessage}" | tee -a $log_location echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}" | tee -a $log_location
else else
echo "$timestamp" : "${log_priority} : $label : ${logmessage}" echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}"
fi fi
done <<< "$log_message" done <<< "$log_message"
fi fi