@@ -108,35 +108,42 @@ export class SWOConsoleProcessor implements SWORTTDecoder {
108
108
}
109
109
}
110
110
111
+ private logFileWrite ( text : string ) {
112
+ if ( ( this . logFd < 0 ) || ( text === '' ) ) {
113
+ return ;
114
+ }
115
+ try {
116
+ fs . writeSync ( this . logFd , text ) ;
117
+ }
118
+ catch ( e ) {
119
+ const msg = `Could not write to file ${ this . logfile } . ${ e . toString ( ) } ` ;
120
+ vscode . window . showErrorMessage ( msg ) ;
121
+ try { fs . closeSync ( this . logFd ) ; } catch { }
122
+ this . logFd = - 1 ;
123
+ }
124
+ }
125
+
111
126
public softwareEvent ( packet : Packet ) {
112
127
if ( packet . port !== this . port ) { return ; }
128
+ let text = '' ;
113
129
const letters = packet . data . toString ( this . encoding ) ;
114
-
115
- if ( this . logFd >= 0 ) {
116
- try {
117
- fs . writeSync ( this . logFd , letters ) ;
118
- }
119
- catch ( e ) {
120
- const msg = `Could not write to file ${ this . logfile } for writing. ${ e . toString ( ) } ` ;
121
- vscode . window . showErrorMessage ( msg ) ;
122
- try { fs . closeSync ( this . logFd ) ; } catch { }
123
- this . logFd = - 1 ;
124
- }
125
- }
126
-
127
130
for ( const letter of letters ) {
128
131
if ( this . timeout ) { clearTimeout ( this . timeout ) ; this . timeout = null ; }
129
132
130
133
if ( letter === '\n' ) {
134
+ text += '\n' ;
131
135
this . pushOutput ( '\n' ) ;
132
136
this . position = 0 ;
133
137
continue ;
134
138
}
135
139
136
140
if ( this . position === 0 ) {
137
- this . pushOutput ( this . createDateHeaderUs ( ) ) ;
141
+ const timestampHeader = this . createDateHeaderUs ( ) ;
142
+ text += timestampHeader ;
143
+ this . pushOutput ( timestampHeader ) ;
138
144
}
139
145
146
+ text += letter ;
140
147
this . pushOutput ( letter ) ;
141
148
this . position += 1 ;
142
149
@@ -145,12 +152,14 @@ export class SWOConsoleProcessor implements SWORTTDecoder {
145
152
clearTimeout ( this . timeout ) ;
146
153
}
147
154
this . timeout = setTimeout ( ( ) => {
155
+ text += '\n' ;
148
156
this . pushOutput ( '\n' ) ;
149
157
this . position = 0 ;
150
158
this . timeout = null ;
151
159
} , 5000 ) ;
152
160
}
153
161
}
162
+ this . logFileWrite ( text ) ;
154
163
}
155
164
156
165
public hardwareEvent ( event : Packet ) { }
0 commit comments