Skip to content

Commit a5ba64d

Browse files
committed
refactor: Improve naming of 'stdtrace.log' function
1 parent 2186d50 commit a5ba64d

File tree

5 files changed

+48
-52
lines changed

5 files changed

+48
-52
lines changed

pkg/src/parse.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ bash_object.parse_virtual_object() {
174174
local virtual_object_name="${virtual_object#*&}" # __bash_object_383028
175175

176176
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
177-
stdtrace.log 2 "virtual_object: '$virtual_object'"
178-
stdtrace.log 2 "virtual_metadatas: '$virtual_metadatas'"
179-
stdtrace.log 2 "virtual_object_name: '$virtual_object_name'"
177+
bash_object.trace_print 2 "virtual_object: '$virtual_object'"
178+
bash_object.trace_print 2 "virtual_metadatas: '$virtual_metadatas'"
179+
bash_object.trace_print 2 "virtual_object_name: '$virtual_object_name'"
180180
fi
181181

182182
# Parse info about the virtual object
@@ -191,9 +191,9 @@ bash_object.parse_virtual_object() {
191191
vmd_value="${vmd#*=}"
192192

193193
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
194-
stdtrace.log 2 "vmd: '$vmd'"
195-
stdtrace.log 3 "vmd_key: '$vmd_key'"
196-
stdtrace.log 3 "vmd_value: '$vmd_value'"
194+
bash_object.trace_print 2 "vmd: '$vmd'"
195+
bash_object.trace_print 3 "vmd_key: '$vmd_key'"
196+
bash_object.trace_print 3 "vmd_value: '$vmd_value'"
197197
fi
198198

199199
case "$vmd_key" in

pkg/src/traverse-get.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ bash_object.traverse-get() {
44
unset REPLY; REPLY=
55

66
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
7-
stdtrace.log 0 ''
8-
stdtrace.log 0 "CALL: bash_object.traverse-get: $*"
7+
bash_object.trace_print 0 ''
8+
bash_object.trace_print 0 "CALL: bash_object.traverse-get: $*"
99
fi
1010

1111
local flag_as_what=
@@ -103,7 +103,7 @@ bash_object.traverse-get() {
103103
# If 'key_value' is a virtual object, dereference it
104104
if [ "${key_value::2}" = $'\x1C\x1D' ]; then
105105
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
106-
stdtrace.log 2 "BLOCK: OBJECT/ARRAY"
106+
bash_object.trace_print 2 "BLOCK: OBJECT/ARRAY"
107107
fi
108108

109109
local old_current_object_name="$current_object_name"
@@ -233,7 +233,7 @@ bash_object.traverse-get() {
233233
# Otherwise, 'key_value' is a string
234234
else
235235
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
236-
stdtrace.log 2 "BLOCK: STRING"
236+
bash_object.trace_print 2 "BLOCK: STRING"
237237
fi
238238

239239
if ((i+1 < ${#REPLIES[@]})); then
@@ -266,7 +266,7 @@ bash_object.traverse-get() {
266266

267267
bash_object.trace_current_object
268268
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
269-
stdtrace.log 0 "END BLOCK"
269+
bash_object.trace_print 0 "END BLOCK"
270270
fi
271271
done; unset i
272272
}

pkg/src/traverse-set.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
bash_object.traverse-set() {
44
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
5-
stdtrace.log 0 ''
6-
stdtrace.log 0 "CALL: bash_object.traverse-set: $*"
5+
bash_object.trace_print 0 ''
6+
bash_object.trace_print 0 "CALL: bash_object.traverse-set: $*"
77
fi
88

99
local flag_pass_by_what=
@@ -300,7 +300,7 @@ bash_object.traverse-set() {
300300
# If 'key_value' is a virtual object, dereference it
301301
if [ "${key_value::2}" = $'\x1C\x1D' ]; then
302302
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
303-
stdtrace.log 2 "BLOCK: OBJECT/ARRAY"
303+
bash_object.trace_print 2 "BLOCK: OBJECT/ARRAY"
304304
fi
305305

306306
local old_current_object_name="$current_object_name"
@@ -404,7 +404,7 @@ bash_object.traverse-set() {
404404
# Otherwise, 'key_value' is a string
405405
else
406406
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
407-
stdtrace.log 2 "BLOCK: STRING"
407+
bash_object.trace_print 2 "BLOCK: STRING"
408408
fi
409409

410410
if ((i+1 < ${#REPLIES[@]})); then
@@ -431,7 +431,7 @@ bash_object.traverse-set() {
431431

432432
bash_object.trace_current_object
433433
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
434-
stdtrace.log 0 "END BLOCK"
434+
bash_object.trace_print 0 "END BLOCK"
435435
fi
436436
done; unset i
437437
}

pkg/src/util/trace.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,42 @@
22

33
bash_object.trace_loop() {
44
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
5-
stdtrace.log 0 "-- START LOOP ITERATION"
6-
stdtrace.log 0 "i+1: '$((i+1))'"
7-
stdtrace.log 0 "\${#REPLIES[@]}: ${#REPLIES[@]}"
8-
stdtrace.log 0 "key: '$key'"
9-
stdtrace.log 0 "current_object_name: '$current_object_name'"
10-
stdtrace.log 0 "current_object=("
5+
bash_object.trace_print 0 "-- START LOOP ITERATION"
6+
bash_object.trace_print 0 "i+1: '$((i+1))'"
7+
bash_object.trace_print 0 "\${#REPLIES[@]}: ${#REPLIES[@]}"
8+
bash_object.trace_print 0 "key: '$key'"
9+
bash_object.trace_print 0 "current_object_name: '$current_object_name'"
10+
bash_object.trace_print 0 "current_object=("
1111
for debug_key in "${!current_object[@]}"; do
12-
stdtrace.log 0 " [$debug_key]='${current_object[$debug_key]}'"
12+
bash_object.trace_print 0 " [$debug_key]='${current_object[$debug_key]}'"
1313
done
14-
stdtrace.log 0 ")"
14+
bash_object.trace_print 0 ")"
1515
fi
1616
}
1717

1818
bash_object.trace_current_object() {
1919
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
20-
stdtrace.log 0 "key: '$key'"
21-
stdtrace.log 0 "current_object_name: '$current_object_name'"
22-
stdtrace.log 0 "current_object=("
20+
bash_object.trace_print 0 "key: '$key'"
21+
bash_object.trace_print 0 "current_object_name: '$current_object_name'"
22+
bash_object.trace_print 0 "current_object=("
2323
for debug_key in "${!current_object[@]}"; do
24-
stdtrace.log 0 " [$debug_key]='${current_object[$debug_key]}'"
24+
bash_object.trace_print 0 " [$debug_key]='${current_object[$debug_key]}'"
2525
done
26-
stdtrace.log 0 ")"
26+
bash_object.trace_print 0 ")"
2727
fi
2828
}
29+
30+
bash_object.trace_print() {
31+
local level="$1"
32+
local message="$2"
33+
34+
local padding=
35+
case "$level" in
36+
0) padding= ;;
37+
1) padding=" " ;;
38+
2) padding=" " ;;
39+
3) padding=" " ;;
40+
esac
41+
42+
printf '%s\n' "TRACE $level: $padding| $message" >&3
43+
}

pkg/src/util/util.sh

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ bash_object.util.generate_vobject_name() {
5757
printf -v REPLY '%q' "__bash_object_${root_object_name}___${root_object_query}_${random_string}"
5858
}
5959

60-
# @description Prints the contents of a particular variable
61-
# or vobject
60+
# @description Prints the contents of a particular variable or vobject
6261
bash_object.util.print_hierarchy() {
6362
local object_name="$1"
6463
local current_indent="$2"
@@ -112,8 +111,7 @@ bash_object.util.print_hierarchy() {
112111
fi
113112
}
114113

115-
# @description Prints the contents of a particular variable
116-
# or vobject
114+
# @description Prints the contents of a particular variable or vobject
117115
bash_object.util.unset() {
118116
local object_name="$1"
119117

@@ -155,9 +153,8 @@ bash_object.util.unset() {
155153
fi
156154
}
157155

158-
# @description A stringified version of the querytree
159-
# stack. This is used when generating objects to prevent
160-
# conflicts
156+
# @description A stringified version of the querytree stack. This is used when
157+
# generating objects to prevent conflicts
161158
bash_object.util.generate_querytree_stack_string() {
162159
unset REPLY; REPLY=
163160

@@ -166,19 +163,3 @@ bash_object.util.generate_querytree_stack_string() {
166163
REPLY="${querytree_stack[*]}"
167164
IFS="$oldIFS"
168165
}
169-
170-
# TODO
171-
stdtrace.log() {
172-
local level="$1"
173-
local message="$2"
174-
175-
local padding=
176-
case "$level" in
177-
0) padding= ;;
178-
1) padding=" " ;;
179-
2) padding=" " ;;
180-
3) padding=" " ;;
181-
esac
182-
183-
printf '%s\n' "TRACE $level: $padding| $message" >&3
184-
}

0 commit comments

Comments
 (0)