2936
|
1 |
"{ Package: 'stx:libbasic2' }"
|
|
2 |
|
|
3 |
Stream subclass:#LoggingStream
|
|
4 |
instanceVariableNames:'loggedStream logger'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Streams-Misc'
|
|
8 |
!
|
|
9 |
|
|
10 |
!LoggingStream class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
2945
|
14 |
Useful for debugging - stream operations are logged in human readable form
|
|
15 |
on a separate logger stream, while stream operations are forwarded to the underlying
|
|
16 |
loggedStream.
|
|
17 |
|
|
18 |
Unfinished - may need more protocol to be intercepted.
|
2936
|
19 |
|
2946
|
20 |
sample use, logging operations on a socket stream:
|
|
21 |
sock := ... Socket connectTo: ...
|
|
22 |
s := LoggingStream new loggedStream: sock.
|
|
23 |
...
|
|
24 |
use s instead of sock
|
|
25 |
...
|
|
26 |
|
2936
|
27 |
[author:]
|
|
28 |
cg
|
|
29 |
|
|
30 |
[instance variables:]
|
|
31 |
|
|
32 |
[class variables:]
|
|
33 |
|
|
34 |
[see also:]
|
|
35 |
|
|
36 |
"
|
|
37 |
! !
|
|
38 |
|
|
39 |
!LoggingStream class methodsFor:'instance creation'!
|
|
40 |
|
3288
|
41 |
on:aStream
|
|
42 |
"Create & return a new instance for aStream, logging to the Transcript."
|
2936
|
43 |
|
3288
|
44 |
^ self on:aStream logger:Transcript
|
|
45 |
!
|
|
46 |
|
|
47 |
on:aStream logger:aLoggerStream
|
|
48 |
"Create & return a new instance for aStream, logging to aLoggerStream."
|
|
49 |
|
|
50 |
^ self basicNew initializeOn:aStream logger:aLoggerStream
|
2936
|
51 |
! !
|
|
52 |
|
|
53 |
!LoggingStream methodsFor:'accessing'!
|
|
54 |
|
|
55 |
loggedStream
|
|
56 |
^ loggedStream
|
|
57 |
!
|
|
58 |
|
|
59 |
loggedStream:something
|
|
60 |
loggedStream := something.
|
|
61 |
!
|
|
62 |
|
|
63 |
logger
|
|
64 |
^ logger
|
|
65 |
!
|
|
66 |
|
|
67 |
logger:something
|
|
68 |
logger := something.
|
|
69 |
! !
|
|
70 |
|
|
71 |
!LoggingStream methodsFor:'initialization'!
|
|
72 |
|
|
73 |
initializeOn:aStream logger:aLogger
|
|
74 |
loggedStream := aStream.
|
|
75 |
logger := aLogger.
|
|
76 |
! !
|
|
77 |
|
2947
|
78 |
!LoggingStream methodsFor:'logging'!
|
|
79 |
|
|
80 |
log:messageString
|
|
81 |
logger nextPutLine:messageString.
|
|
82 |
! !
|
|
83 |
|
2936
|
84 |
!LoggingStream methodsFor:'stream protocol'!
|
|
85 |
|
2947
|
86 |
atEnd
|
|
87 |
^ loggedStream atEnd.
|
|
88 |
!
|
|
89 |
|
|
90 |
flush
|
|
91 |
loggedStream flush.
|
|
92 |
!
|
|
93 |
|
2936
|
94 |
next
|
|
95 |
|el|
|
|
96 |
|
|
97 |
el := loggedStream next.
|
2947
|
98 |
self log:( '<<< ' , el storeString ).
|
2936
|
99 |
^ el
|
|
100 |
!
|
|
101 |
|
|
102 |
next:n
|
|
103 |
|els|
|
|
104 |
|
|
105 |
els := loggedStream next:n.
|
2947
|
106 |
self log:( '<<< ' , els storeString ).
|
|
107 |
^ els
|
|
108 |
!
|
|
109 |
|
|
110 |
nextBytes:n
|
|
111 |
|els|
|
|
112 |
|
|
113 |
els := loggedStream nextBytes:n.
|
|
114 |
self log:( '<<< ' , els storeString ).
|
2936
|
115 |
^ els
|
|
116 |
!
|
|
117 |
|
|
118 |
nextPut:something
|
2947
|
119 |
self log:( '>>> ' , something storeString).
|
2936
|
120 |
loggedStream nextPut:something.
|
|
121 |
!
|
|
122 |
|
|
123 |
nextPutAll:aCollection
|
2947
|
124 |
self log:( '>>> ' , aCollection storeString).
|
2936
|
125 |
loggedStream nextPutAll:aCollection.
|
|
126 |
!
|
|
127 |
|
3289
|
128 |
peek
|
|
129 |
^ loggedStream peek
|
|
130 |
!
|
|
131 |
|
|
132 |
peekOrNil
|
|
133 |
^ loggedStream peekOrNil
|
|
134 |
!
|
|
135 |
|
2947
|
136 |
readWait
|
|
137 |
^ loggedStream readWait.
|
|
138 |
!
|
|
139 |
|
3289
|
140 |
skipSeparators
|
|
141 |
|ch|
|
|
142 |
|
|
143 |
[
|
|
144 |
(ch := loggedStream peekOrNil) notNil
|
|
145 |
and:[ch isSeparator]
|
|
146 |
] whileTrue:[
|
|
147 |
self next.
|
|
148 |
].
|
|
149 |
^ ch
|
|
150 |
!
|
|
151 |
|
2936
|
152 |
upToEnd
|
|
153 |
|els|
|
|
154 |
|
|
155 |
els := loggedStream upToEnd.
|
2947
|
156 |
self log:( '<<< ' , els storeString).
|
2936
|
157 |
^ els
|
|
158 |
! !
|
|
159 |
|
|
160 |
!LoggingStream class methodsFor:'documentation'!
|
|
161 |
|
|
162 |
version
|
3289
|
163 |
^ '$Header: /cvs/stx/stx/libbasic2/LoggingStream.st,v 1.7 2014-05-29 10:59:23 cg Exp $'
|
2936
|
164 |
!
|
|
165 |
|
|
166 |
version_CVS
|
3289
|
167 |
^ '$Header: /cvs/stx/stx/libbasic2/LoggingStream.st,v 1.7 2014-05-29 10:59:23 cg Exp $'
|
2936
|
168 |
! !
|
|
169 |
|