Skip to content

Commit 9ca83b2

Browse files
committed
FEAT: extended system's log function with /error refinement
1 parent 065f52e commit 9ca83b2

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

src/boot/sysobj.reb

+6-6
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ options: object [ ; Options supplied to REBOL during startup
152152

153153
; verbosity of logs per service (codecs, schemes)
154154
; 0 = nothing; 1 = info; 2 = more; 3 = debug
155-
log: construct [
156-
http:
157-
tls:
158-
zip:
159-
tar: 1
160-
]
155+
log: #[map! [
156+
http: 1
157+
tls: 1
158+
zip: 1
159+
tar: 1
160+
]]
161161
]
162162

163163
script: construct [

src/mezz/sys-base.reb

+34
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,37 @@ assert-utf8: function [
224224
]
225225
data
226226
]
227+
228+
log: func [
229+
"Prints out debug message"
230+
id [word!] "Source of the log message"
231+
msg "Output message"
232+
/info
233+
/more
234+
/debug
235+
/error
236+
/local level
237+
][
238+
if error [
239+
msg: form either block? msg [reduce msg][msg]
240+
foreach line parse/all msg #"^/" [
241+
print ajoin [
242+
" ^[[35m[" id "] ^[[1m"
243+
either line/1 = #"*" []["** Error: "]
244+
copy/part line 100
245+
"^[[0m"
246+
]
247+
]
248+
exit
249+
]
250+
if system/options/quiet [exit]
251+
level: select system/options/log id
252+
if any [none? level level <= 0] [exit]
253+
if block? msg [msg: form reduce :msg]
254+
case [
255+
info [ if level > 0 [print ajoin [" ^[[1;33m[" id "] ^[[36m" msg "^[[0m"]]]
256+
more [ if level > 1 [print ajoin [" ^[[33m[" id "] ^[[0;36m" msg "^[[0m"]]]
257+
debug [ if level > 2 [print ajoin [" ^[[33m[" id "] ^[[0;32m" msg "^[[0m"]]]
258+
true [ if level > 0 [print ajoin [" ^[[33m[" id "] " msg "^[[0m"]]]
259+
]
260+
]

src/mezz/sys-codec.reb

-20
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,4 @@ encoding?: function [
113113
none
114114
]
115115

116-
log: func [
117-
"Prints out debug message"
118-
id [word!] "Source of the log message"
119-
msg "Output message"
120-
/info
121-
/more
122-
/debug
123-
/local level
124-
][
125-
level: select system/options/log id
126-
if any [none? level level <= 0] [exit]
127-
if block? msg [msg: form reduce :msg]
128-
case [
129-
info [ if level > 0 [print ajoin [" ^[[1;33m[" id "] ^[[36m" msg "^[[0m"]]]
130-
more [ if level > 1 [print ajoin [" ^[[33m[" id "] ^[[0;36m" msg "^[[0m"]]]
131-
debug [ if level > 2 [print ajoin [" ^[[33m[" id "] ^[[0;32m" msg "^[[0m"]]]
132-
true [ if level > 0 [print ajoin [" ^[[33m[" id "] " msg "^[[0m"]]]
133-
]
134-
]
135-
136116
export [register-codec decode encode encoding?]

0 commit comments

Comments
 (0)