-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.tcl
147 lines (116 loc) · 3.58 KB
/
stream.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- tcl -*- Copyright (c) 2012-2024 Andreas Kupries
# # ## ### ##### ######## ############# #####################
## Manage multiple log streams to files.
## Further manage logging to the terminal.
namespace eval ::kettle::stream {
namespace export {[a-z]*}
namespace ensemble create
namespace import ::kettle::option
namespace import ::kettle::io
# Dictonary of open streams.
variable stream {}
}
# # ## ### ##### ######## ############# #####################
## Logging of test/benchmark output, into multiple streams.
## Irrelevant to work database keying.
# Logging is to a set of files, for multiple log 'streams'. The
# option --log specifies their (path) stem. If no stem is specified
# no streams are generated.
kettle option define --log {
Log option. Path (stem) for a set of files to log to
(independent of logging to the terminal).
} {} path
kettle option onchange --log {} { set! --log [path norm $new] }
kettle option no-work-key --log
kettle option define --log-append {
Associate to --log. Open files in append mode.
} off boolean
kettle option no-work-key --log-append
# # ## ### ##### ######## ############# #####################
## Verbosity setting for logging to the terminal.
## Irrelevant to work database keying.
kettle option define --log-mode {
Verbosity of the logging to the terminal by Tcl-based
sub-processes like the execution of testsuites and
benchmarks.
} compact {enum {compact full}}
kettle option no-work-key --log-mode
# # ## ### ##### ######## ############# #####################
## API.
proc ::kettle::stream::active {} {
expr {[option get --log] ne {}}
}
proc ::kettle::stream::to {name text} {
variable stream
if {![active]} return
set text [uplevel 1 [list subst $text]]
if {![dict exists $stream $name]} {
set stem [option get --log]
file mkdir [file dirname $stem.$name]
set mode [expr {[option get --log-append]
? "a"
: "w"}]
set ch [open $stem.$name $mode]
dict set stream $name $ch
} else {
set ch [dict get $stream $name]
}
::puts $ch $text
flush $ch
return
}
proc ::kettle::stream::done {name} {
variable stream
if {![active]} return
if {![dict exists $stream $name]} return
close [dict get $stream $name]
dict unset stream $name
return
}
# # ## ### ##### ######## ############# #####################
## Terminal log.
proc ::kettle::stream::term {mode text} {
if {($mode ne "always") &&
($mode ne [option get --log-mode])} return
io puts $text
return
}
proc ::kettle::stream::aopen {} {
if {[option get --log-mode] ne "compact"} return
io animation begin
return
}
proc ::kettle::stream::aclose {text} {
upvar 1 state state
if {[option get --log-mode] eq "compact"} {
io animation last $text
}
if {![active]} return
set file [file tail [dict get $state file]]
if {[dict exists $state fmap $file]} {
set file [dict get $state fmap $file]
}
set text "$file $text"
to summary {$text}
# Maybe use a mapping table here instead, status to stream.
switch -exact -- [dict get $state suite/status] {
error -
fail { to failures {$text} }
none { to none {$text} }
aborted { to aborted {$text} }
}
return
}
proc ::kettle::stream::aextend {text} {
if {[option get --log-mode] ne "compact"} return
io animation indent $text
io animation write ""
return
}
proc ::kettle::stream::awrite {text} {
if {[option get --log-mode] ne "compact"} return
io animation write $text
return
}
# # ## ### ##### ######## ############# #####################
return