@@ -74,13 +74,18 @@ export async function activate(
74
74
getLogger ( ) . debug ( `Logging started: ${ logUri } ` )
75
75
76
76
const commands = new Logging ( logUri , mainLogger )
77
- extensionContext . subscriptions . push (
78
- ...Object . values ( Logging . declared ) . map ( c => c . register ( commands ) ) ,
79
- await createLogWatcher ( logUri . fsPath )
80
- )
77
+ extensionContext . subscriptions . push ( ...Object . values ( Logging . declared ) . map ( c => c . register ( commands ) ) )
78
+
79
+ createLogWatcher ( logUri )
80
+ . then ( sub => {
81
+ extensionContext . subscriptions . push ( sub )
82
+ } )
83
+ . catch ( err => {
84
+ getLogger ( ) . warn ( 'Failed to start log file watcher: %s' , err )
85
+ } )
81
86
82
87
cleanLogFiles ( path . dirname ( logUri . fsPath ) ) . catch ( err => {
83
- getLogger ( ) . warn ( 'Failed to clean-up old logs: %s' , ( err as Error ) . message )
88
+ getLogger ( ) . warn ( 'Failed to clean-up old logs: %s' , err )
84
89
} )
85
90
}
86
91
@@ -152,25 +157,24 @@ function makeLogFilename(): string {
152
157
/**
153
158
* Watches for renames on the log file and notifies the user.
154
159
*/
155
- async function createLogWatcher ( logPath : string ) : Promise < vscode . Disposable > {
156
- const exists = await waitUntil ( ( ) => fs . pathExists ( logPath ) , { interval : 1000 , timeout : 60000 } )
160
+ async function createLogWatcher ( logFile : vscode . Uri ) : Promise < vscode . Disposable > {
161
+ const exists = await waitUntil ( ( ) => SystemUtilities . fileExists ( logFile ) , { interval : 1000 , timeout : 60000 } )
157
162
158
163
if ( ! exists ) {
159
- getLogger ( ) . warn ( `Log file ${ logPath } does not exist!` )
164
+ getLogger ( ) . warn ( `Log file ${ logFile . path } does not exist!` )
160
165
return { dispose : ( ) => { } }
161
166
}
162
167
163
168
let checking = false
164
169
// TODO: fs.watch() has many problems, consider instead:
165
170
// - https://github.com/paulmillr/chokidar
166
171
// - https://www.npmjs.com/package/fb-watchman
167
- const watcher = fs . watch ( logPath , async eventType => {
172
+ const watcher = fs . watch ( logFile . fsPath , async eventType => {
168
173
if ( checking || eventType !== 'rename' ) {
169
174
return
170
175
}
171
176
checking = true
172
- const exists = await fs . pathExists ( logPath ) . catch ( ( ) => true )
173
- if ( ! exists ) {
177
+ if ( ! ( await SystemUtilities . fileExists ( logFile ) ) ) {
174
178
vscode . window . showWarningMessage (
175
179
localize ( 'AWS.log.logFileMove' , 'The log file for this session has been moved or deleted.' )
176
180
)
0 commit comments