@@ -35,12 +35,15 @@ export class Logger implements ILogger {
35
35
private logChannel : vscode . OutputChannel ;
36
36
private logFilePath : vscode . Uri ;
37
37
private logDirectoryCreated = false ;
38
+ private writingLog = false ;
38
39
39
40
constructor ( logLevelName : string , globalStorageUri : vscode . Uri ) {
40
41
this . logLevel = Logger . logLevelNameToValue ( logLevelName ) ;
41
42
this . logChannel = vscode . window . createOutputChannel ( "PowerShell Extension Logs" ) ;
43
+ // We have to override the scheme because it defaults to
44
+ // 'vscode-userdata' which breaks UNC paths.
42
45
this . logDirectoryPath = vscode . Uri . joinPath (
43
- globalStorageUri ,
46
+ globalStorageUri . with ( { scheme : "file" } ) ,
44
47
"logs" ,
45
48
`${ Math . floor ( Date . now ( ) / 1000 ) } -${ vscode . env . sessionId } ` ) ;
46
49
this . logFilePath = this . getLogFilePath ( "vscode-powershell" ) ;
@@ -194,11 +197,16 @@ export class Logger implements ILogger {
194
197
const timestampedMessage = Logger . timestampMessage ( message , level ) ;
195
198
this . logChannel . appendLine ( timestampedMessage ) ;
196
199
if ( this . logLevel !== LogLevel . None ) {
200
+ // A simple lock because this function isn't re-entrant.
201
+ while ( this . writingLog ) {
202
+ await utils . sleep ( 300 ) ;
203
+ }
197
204
try {
205
+ this . writingLog = true ;
198
206
if ( ! this . logDirectoryCreated ) {
199
207
this . logChannel . appendLine ( Logger . timestampMessage ( `Creating log directory at: '${ this . logDirectoryPath } '` , level ) ) ;
200
208
await vscode . workspace . fs . createDirectory ( this . logDirectoryPath ) ;
201
- this . logDirectoryCreated = await utils . checkIfDirectoryExists ( this . logDirectoryPath ) ;
209
+ this . logDirectoryCreated = true ;
202
210
}
203
211
let log = new Uint8Array ( ) ;
204
212
if ( await utils . checkIfFileExists ( this . logFilePath ) ) {
@@ -209,6 +217,8 @@ export class Logger implements ILogger {
209
217
Buffer . concat ( [ log , Buffer . from ( timestampedMessage ) ] ) ) ;
210
218
} catch ( e ) {
211
219
console . log ( `Error writing to vscode-powershell log file: ${ e } ` ) ;
220
+ } finally {
221
+ this . writingLog = false ;
212
222
}
213
223
}
214
224
}
0 commit comments