1 # vim: foldmarker=<<<,>>>
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
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)"
45 body tlc
::Log::constructor {args
} { #<<<1
46 array set highlights
{}
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
73 if {[string is integer
-strict $threshold_str]} {
75 } elseif
{[info exists levels
($threshold_str)]} {
76 return $levels($threshold_str)
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