add proper logging function
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Joe 2021-10-14 20:29:08 -05:00
parent 556fe05d0d
commit df57225b1c
Signed by: joe
GPG Key ID: 8595A3F8F2CE1B74
8 changed files with 61 additions and 14 deletions

View File

@ -3,7 +3,9 @@ ReadConfiguration
CreateFiles
InitCheck
Clean
DebugPrint
Log
LogTerm
LogFile
ProcessBuildFile
BuildProject
InitProject

View File

@ -14,18 +14,18 @@ BuildProject() {
arg="${arg#?}"
case "$arg" in
d )
DebugPrint "Debug build enabled."
DebugPrint "Args are $*"
DebugPrint "Arg is $arg"
Log debug "Debug build enabled."
Log debug "Args are $*"
Log debug "Arg is $arg"
for ((i=0;i<"${#files[*]}";i++));do
find "${files[$i]}" -type f -print0 | xargs -0 cat;
done >> "${config[build_path]}""$name"
;;
* )
DebugPrint "Stripped build enabled."
DebugPrint "Args are $*"
DebugPrint "Arg is $arg"
Log debug "Stripped build enabled."
Log debug "Args are $*"
Log debug "Arg is $arg"
for ((i=0;i<"${#files[*]}";i++));do
grep -Ehrv '^\s*\#' "${files[$i]}";
done >> "${config[build_path]}""$name"

View File

@ -3,9 +3,12 @@ Configure() {
config=(
[config_path]="config"
[config_file]="linac.conf"
[verbosity]="error"
[log_level]="info"
[log_path]="/tmp"
[log_file]="linac.log"
[src_path]="src/"
[build_path]="build/"
[debug_enabled]="false"
)
# echo ${config[build_path]}
}

4
src/Log Normal file
View File

@ -0,0 +1,4 @@
Log() {
LogTerm "$1" "$2"
LogFile "$1" "$2"
}

19
src/LogFile Normal file
View File

@ -0,0 +1,19 @@
LogFile() {
local file_log_type="${1^^}"
local file_log_message="$2"
local log_level="${config[log_level]^^}"
DoLogFile() {
echo "[$(date '+%d/%b/%Y:%H:%M:%S.%3N')] ${file_log_type} - ${FUNCNAME[3]}: $file_log_message" >> "${config[log_path]}/${config[log_file]}"
}
case $file_log_type in
DEBUG ) if [[ "$log_level" = @(DEBUG) ]]; then DoLogFile; fi;;
INFO ) if [[ "$log_level" = @(DEBUG|INFO) ]]; then DoLogFile; fi;;
WARN ) if [[ "$log_level" = @(DEBUG|INFO|WARN) ]]; then DoLogFile; fi;;
ERROR ) if [[ "$log_level" = @(DEBUG|INFO|WARN|ERROR) ]]; then DoLogFile; fi;;
CONFIG ) if [[ "$log_level" != @(NONE) ]]; then DoLogFile; fi;;
* ) if [[ "$log_level" = @(DEBUG) ]]; then DoLogFile; Log debug "Invalid file log type '$file_log_type' in context '${FUNCNAME[2]}'"; fi;;
esac
}

19
src/LogTerm Normal file
View File

@ -0,0 +1,19 @@
LogTerm() {
local term_log_type="${1^^}"
local term_log_message="$2"
local verbosity="${config[verbosity]^^}"
DoLogTerm() {
echo "$term_log_type - $term_log_message"
}
case $term_log_type in
DEBUG ) if [[ "$verbosity" = @(DEBUG) ]]; then DoLogTerm; fi;;
INFO ) if [[ "$verbosity" = @(DEBUG|INFO) ]]; then DoLogTerm; fi;;
WARN ) if [[ "$verbosity" = @(DEBUG|INFO|WARN) ]]; then DoLogTerm; fi;;
ERROR ) if [[ "$verbosity" = @(DEBUG|INFO|WARN|ERROR) ]]; then DoLogTerm; fi;;
CONFIG ) if [[ "$verbosity" = @(DEBUG|INFO) ]]; then DoLogTerm; fi;;
* ) if [[ "$verbosity" = @(DEBUG) ]]; then DoLogTerm; Log debug "Invalid term log type '$term_log_type' in context '${FUNCNAME[2]}'"; fi;;
esac
}

View File

@ -1,6 +1,8 @@
Main() {
PrintInfo
Configure
ReadConfiguration
SubCommand "$@"
}
PrintInfo
Main "$@"

View File

@ -18,12 +18,10 @@ SubCommand() {
fi
;;
* )
Configure
ReadConfiguration
DebugPrint "Args are $*"
Log debug "Args are $*"
shift
DebugPrint "Shifted args"
DebugPrint "Args are $*"
Log debug "Shifted args"
Log debug "Args are $*"
if ! command -v Sub"${subcommand^}" > /dev/null; then
echo "Error: '$subcommand' is not a known command."
echo " Run 'linac help' for a list of known commands."