Improved handling of case where child is killed by a signal
[tcl-tlc.git] / scripts / log.itcl
blobe021bf00b302c4c90509b0cbf6f1e62db319b975
1 # vim: foldmarker=<<<,>>>
3 class tlc::Log {
4 constructor {args} {}
6 public {
7 variable threshold 20
9 method custom {level args} {eval output [list $level] $args}
10 method trivia {args} {eval output 5 $args}
11 method debug {args} {eval output 10 $args}
12 method notify {args} {eval output 20 $args}
13 method notice {args} {eval output 20 $args}
14 method warning {args} {eval output 30 $args}
15 method warn {args} {eval output 30 $args}
16 method error {args} {eval output 40 $args}
17 method fatal {args} {eval output 50 $args}
19 method set_highlight {regex colour}
20 method unset_highlight {regex}
23 # Overload these and add methods above to add new levels
24 protected {
25 variable highlights
27 method output {level msg}
28 method lookup_threshold {threshold_str}
33 configbody tlc::Log::threshold { #<<<1
34 if {![string is integer -strict $threshold]} {
35 set res [lookup_threshold $threshold]
36 if {![string is integer -strict $res]} {
37 error "Log: Threshold specified ($threshold) is not valid. Must be one of ($res)"
38 } else {
39 set threshold $res
45 body tlc::Log::constructor {args} { #<<<1
46 array set highlights {}
48 eval configure $args
52 body tlc::Log::output {level msg} { #<<<1
53 if {$level >= $threshold} {
54 foreach {regex colour} [array get highlights] {
55 set msg [regsub -all $regex $msg "\e\[${colour}m&\\e\[0m"]
57 puts stderr "[clock format [clock seconds] -format {%d/%m/%Y %T}] $level $msg"
62 body tlc::Log::lookup_threshold {threshold_str} { #<<<1
63 array set levels {
64 trivia 5
65 debug 10
66 notice 20
67 notify 20
68 warning 30
69 error 40
70 fatal 50
73 if {[string is integer -strict $threshold_str]} {
74 return $threshold_str
75 } elseif {[info exists levels($threshold_str)]} {
76 return $levels($threshold_str)
77 } else {
78 return [array names levels]
83 body tlc::Log::set_highlight {regex colour} { #<<<1
84 set highlights($regex) $colour
88 body tlc::Log::unset_highlight {regex} { #<<<1
89 array unset highlights $regex