@@ -498,30 +498,31 @@ function log::printFile() {
498498# Display a file content with line numbers in the logs.
499499# The file content will be aligned with the current log output and hard wrapped if necessary.
500500#
501- # - $1: **content** _as string_:
502- # the file content.
501+ # - $1: **content variable name ** _as string_:
502+ # The name of the variable containing the file content to print .
503503# - $2: max lines _as int_:
504504# (optional) Can be set using the variable `_OPTION_MAX_LINES`.
505505# Max lines to display, can be set to 0 to display all lines.
506506# (defaults to 0)
507507#
508508# ```bash
509- # log::printFileString "myfilecontent "
509+ # log::printFileString "myvar "
510510# ```
511511#
512512# > This function is not at all suited for large strings, print the content to a file instead.
513513# shellcheck disable=SC2317
514514function log::printFileString() {
515- local content =" ${1?" The function ⌜${FUNCNAME:- ?} ⌝ requires more than $# arguments." } "
515+ local -n contentToPrint =" ${1?" The function ⌜${FUNCNAME:- ?} ⌝ requires more than $# arguments." } "
516516 local -i maxLines=" ${2:- ${_OPTION_MAX_LINES:- 0} } "
517517
518518 local line toPrint lineNumberPadding=" "
519519 local -i lineNumber=1 currentLineNumberLength=1
520- while (( ${ # content} > 0 )) ; do
521- line= " ${content %% $' \n ' * } "
522- content= " ${content : ${ # line} + 1} "
520+
521+ local IFS
522+ while IFS= $' \n ' read -rd $' \n ' line; do
523523 log::printFileInternalLoop || break ;
524- done
524+ done <<< " ${contentToPrint}"
525+
525526 # evaluated the print statement built in log::init; it uses the local var toPrint defined above
526527 eval " ${GLOBAL_LOG_PRINT_STATEMENT_STANDARD} "
527528}
@@ -629,8 +630,8 @@ function log::saveFile() {
629630# (using `core::createNewStateFilePath`).
630631# Useful for debugging purposes, to save the state of a string during execution.
631632#
632- # - $1: **content** _as string_:
633- # The content to save.
633+ # - $1: **content variable name ** _as string_:
634+ # The variable name of the content to save.
634635# - $2: **suffix** _as string_:
635636# The suffix to add to the file name.
636637# - $3: log path _as bool_:
@@ -645,12 +646,12 @@ function log::saveFile() {
645646# log::saveFileString "my content" "suffix" "important result file"
646647# ```
647648function log::saveFileString() {
648- local content =" ${1?" The function ⌜${FUNCNAME:- ?} ⌝ requires more than $# arguments." } "
649+ local -n contentToSave =" ${1?" The function ⌜${FUNCNAME:- ?} ⌝ requires more than $# arguments." } "
649650 local suffix=" ${2?" The function ⌜${FUNCNAME:- ?} ⌝ requires more than $# arguments." } "
650651 local logPath=" ${3:- " true" } "
651652 core::createNewStateFilePath " ${suffix} "
652653 local newFilePath=" ${RETURNED_VALUE} "
653- printf ' %s' " ${content } " > " ${newFilePath} "
654+ printf ' %s' " ${contentToSave } " > " ${newFilePath} "
654655 if [[ ${logPath} == " true" ]]; then
655656 log::printString " ⌜${newFilePath} ⌝"
656657 fi
@@ -662,17 +663,17 @@ function log::saveFileString() {
662663# Display something in the log stream.
663664# Does not check the log level.
664665#
665- # - $1: **content** _as string_:
666- # the content to print (can contain new lines)
666+ # - $1: **content variable name ** _as string_:
667+ # The variable name containing the content to print (can contain new lines).
667668#
668669# ```bash
669670# log::printRaw "my line"
670671# ```
671672# shellcheck disable=SC2317
672673function log::printRaw() {
673- local IFS= $' \n '
674+ local -n toPrint= " ${1? " The function ⌜ ${FUNCNAME :- ?} ⌝ requires more than $# arguments. " } "
674675 # shellcheck disable=SC2034
675- local toPrint= " $* "
676+
676677 # evaluated the print statement built in log::init; it uses the local var toPrint defined above
677678 eval " ${GLOBAL_LOG_PRINT_STATEMENT_STANDARD} "
678679}
0 commit comments