From 5368cd75e8086a71af7616918773f13d8d54d32b Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 30 Aug 2023 14:02:22 +0100 Subject: logging! --- bos-args.sh | 2 +- bos-log.sh | 5 +++++ bos-meta-attribute.sh | 8 ++++---- bos-meta-class.sh | 6 +++--- bos-sugar.sh | 4 ++-- bos.sh | 1 + 6 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 bos-log.sh diff --git a/bos-args.sh b/bos-args.sh index 69c27d8..dfe4be2 100644 --- a/bos-args.sh +++ b/bos-args.sh @@ -16,7 +16,7 @@ function bos-args/build-parser-code-into() { shift 2 ;; *) - >&2 echo "bad argument <$1>"; + bos/log 1 "bad argument <$1>"; return 1 ;; esac diff --git a/bos-log.sh b/bos-log.sh new file mode 100644 index 0000000..3451970 --- /dev/null +++ b/bos-log.sh @@ -0,0 +1,5 @@ +function bos/log() { + { + [[ ${BOS_LOG_THRESHOLD:-1} -ge "$1" ]] && shift && >&2 echo "$*" + } || true +} diff --git a/bos-meta-attribute.sh b/bos-meta-attribute.sh index 1153d3a..954ea8d 100644 --- a/bos-meta-attribute.sh +++ b/bos-meta-attribute.sh @@ -33,7 +33,7 @@ function bos/meta/attribute/get-attribute-name-into() { local -n bos_meta_attribute_name="$bos_meta_attribute_name_store" - >&2 echo "get-attribute-name-into($1)<-$bos_meta_attribute_name_store" + bos/log 5 "get-attribute-name-into($1)<-$bos_meta_attribute_name_store" local -n bos_meta_attribute_name_dest="$1" bos_meta_attribute_name_dest="$bos_meta_attribute_name" } @@ -88,7 +88,7 @@ function bos/meta/attribute/set-value() { assoc) eval "bos_meta_attribute_store=( ${@@Q} )" ;; esac - >&2 echo -n 'set-value()'; >&2 declare -p "$bos_meta_attribute_store_name" + bos/log 5 "set-value() $(declare -p "$bos_meta_attribute_store_name")" return 0 } @@ -108,7 +108,7 @@ function bos/meta/attribute/get-value-into() { local attribute_type="$bos_meta_attribute_get_type" local associated_class="$bos_meta_attribute_get_class" - >&2 echo "getting ($self) ($attribute_name) ($attribute_type) ($associated_class) ($1)" + bos/log 5 "getting ($self) ($attribute_name) ($attribute_type) ($associated_class) ($1)" local bos_meta_attribute_store_name; $self store-for-into bos_meta_attribute_store_name "$1" local -n bos_meta_attribute_store="$bos_meta_attribute_store_name" @@ -126,7 +126,7 @@ function bos/meta/attribute/get-value-into() { ;; esac - >&2 declare -p "$bos_meta_attribute_result_name" + bos/log 5 "$(declare -p "$bos_meta_attribute_result_name")" return 0 } diff --git a/bos-meta-class.sh b/bos-meta-class.sh index a02ddb1..63a9361 100644 --- a/bos-meta-class.sh +++ b/bos-meta-class.sh @@ -95,7 +95,7 @@ function bos/meta/class/find-method-into() { done # TODO: better error / failure - >&2 echo "method $method not found via class $class" + bos/log 1 "method $method not found via class $class" return 1 } @@ -103,7 +103,7 @@ function bos/meta/class/find-method-into() { # that the class that this metaclass describe, actuall has that # attribute function bos/meta/class/get-attribute-by-name-into() { - >&2 echo "get-attribute-by-name-into($*)" + bos/log 5 "get-attribute-by-name-into($*)" local -n bos_meta_class_get_attribute_result="$1"; shift local bos_meta_class_get_attribute_name="$1" local bos_meta_class_attrs_name @@ -177,7 +177,7 @@ function bos/meta/class/invoke() { local bos_invoke_attrs_attr $bos_invoke_target_metaclass_instance get-attribute-by-name-into bos_invoke_attrs_attr 'class_attributes' - >&2 echo "for (${bos_invoke_class}->${bos_invoke_target_class}) class_attributes = $bos_invoke_attrs_attr" + bos/log 5 "for (${bos_invoke_class}->${bos_invoke_target_class}) class_attributes = $bos_invoke_attrs_attr" if [[ -n "$bos_invoke_attrs_attr" ]]; then local -A bos_invoke_attrs diff --git a/bos-sugar.sh b/bos-sugar.sh index 152f5d8..add408a 100644 --- a/bos-sugar.sh +++ b/bos-sugar.sh @@ -45,7 +45,7 @@ function bos-sugar/remove-helpers() { function bos-sugar/class-open() { if [[ "${#*}" -lt 1 || "${#*}" -gt 2 ]]; then - >&2 echo "'class \$class_name [\$metaclass]; do …; done', not 'class $*'" + bos/log 1 "'class \$class_name [\$metaclass]; do …; done', not 'class $*'" return 1 fi local class="$1" @@ -86,7 +86,7 @@ bos-sugar/declare-block class bos-sugar/class-open bos-sugar/class-close function bos-sugar/namespace-open() { if [[ "${#*}" -ne 1 ]]; then - >&2 echo "'namespace \$namespace_name; do …; done', not 'namespace $*'" + bos/log 1 "'namespace \$namespace_name; do …; done', not 'namespace $*'" return 1 fi diff --git a/bos.sh b/bos.sh index fe7fc0d..7859597 100644 --- a/bos.sh +++ b/bos.sh @@ -3,6 +3,7 @@ if [[ -z "$bos_inited" ]]; then set -e + . bos-log.sh . bos-args.sh . bos-dispatch.sh . bos-namespaces.sh -- cgit v1.2.3