@@ -8,17 +8,19 @@ import { sendInfo } from "vscode-extension-telemetry-wrapper";
88import { LSDaemon } from "../daemon" ;
99import { collectErrors , collectErrorsSince , logsForLatestSession , sessionMetadata } from "./logUtils" ;
1010import { toElapsed } from "./utils" ;
11+ import { redact } from "./whitelist" ;
1112
1213export class LogWatcher {
1314 private serverLogUri : vscode . Uri | undefined ;
1415 private logProcessedTimestamp : number = Date . now ( ) ;
1516 private context : vscode . ExtensionContext ;
17+ private watcher : vscode . FileSystemWatcher | undefined ;
1618 constructor ( daemon : LSDaemon ) {
1719 this . context = daemon . context ;
1820 if ( this . context . storageUri ) {
1921 const javaExtStoragePath : string = path . join ( this . context . storageUri . fsPath , ".." , "redhat.java" ) ;
2022 const serverLogPath : string = path . join ( javaExtStoragePath , "jdt_ws" , ".metadata" ) ;
21- this . serverLogUri = this . context . storageUri . with ( { path : serverLogPath } ) ;
23+ this . serverLogUri = this . context . storageUri . with ( { path : serverLogPath } ) ;
2224 }
2325 }
2426
@@ -27,20 +29,20 @@ export class LogWatcher {
2729 */
2830 public async start ( ) {
2931 if ( ! this . serverLogUri ) {
30- sendInfo ( "" , { name : "no-server-log" } ) ;
32+ sendInfo ( "" , { name : "no-server-log" } ) ;
3133 return ;
32- }
34+ }
3335
3436 try {
3537 await fs . promises . access ( this . serverLogUri . fsPath ) ;
3638 } catch ( error ) {
37- sendInfo ( "" , { name : "no-server-log" } ) ;
39+ sendInfo ( "" , { name : "no-server-log" } ) ;
3840 return ;
3941 }
4042
41- const watcher = vscode . workspace . createFileSystemWatcher ( new vscode . RelativePattern ( this . serverLogUri , "*.log" ) ) ;
42- watcher . onDidChange ( async ( e ) => {
43- if ( Date . now ( ) - this . logProcessedTimestamp < 1000 ) { return ; } // reduce frequency of log file I/O.
43+ this . watcher = vscode . workspace . createFileSystemWatcher ( new vscode . RelativePattern ( this . serverLogUri , "*.log" ) ) ;
44+ this . watcher . onDidChange ( async ( e ) => {
45+ if ( Date . now ( ) - this . logProcessedTimestamp < 1000 ) { return ; } // reduce frequency of log file I/O.
4446 const logs = await logsForLatestSession ( e . fsPath ) ;
4547 const errors = collectErrorsSince ( logs , this . logProcessedTimestamp ) ;
4648 const consentToCollectLogs = vscode . workspace . getConfiguration ( "java" ) . get < boolean > ( "help.shareDiagnostics" ) ;
@@ -53,6 +55,7 @@ export class LogWatcher {
5355 timestamp : e . timestamp ! . toString ( )
5456 } ) : sendInfo ( "" , {
5557 name : "jdtls-error" ,
58+ error : redact ( e . message ) ,
5659 timestamp : e . timestamp ! . toString ( )
5760 } ) ;
5861 } )
@@ -61,13 +64,20 @@ export class LogWatcher {
6164 } ) ;
6265 }
6366
67+ public stop ( ) {
68+ if ( this . watcher ) {
69+ this . watcher . dispose ( )
70+ this . watcher = undefined ;
71+ }
72+ }
73+
6474 /**
6575 * metadata
6676 */
6777 public async sendStartupMetadata ( remark ?: string ) {
68- if ( this . serverLogUri ) {
69- const logs = await logsForLatestSession ( path . join ( this . serverLogUri ?. fsPath , ".log" ) ) ;
70- const metadata = sessionMetadata ( logs ) ;
78+ if ( this . serverLogUri ) {
79+ const logs = await logsForLatestSession ( path . join ( this . serverLogUri ?. fsPath , ".log" ) ) ;
80+ const metadata = sessionMetadata ( logs ) ;
7181 sendInfo ( "" , {
7282 name : "jdtls-startup-metadata" ,
7383 remark : remark ! ,
@@ -84,8 +94,8 @@ export class LogWatcher {
8494 }
8595
8696 public async sendErrorAndStackOnCrash ( ) {
87- if ( this . serverLogUri ) {
88- const logs = await logsForLatestSession ( path . join ( this . serverLogUri ?. fsPath , ".log" ) ) ;
97+ if ( this . serverLogUri ) {
98+ const logs = await logsForLatestSession ( path . join ( this . serverLogUri ?. fsPath , ".log" ) ) ;
8999 const errors = collectErrors ( logs ) ;
90100 const consentToCollectLogs = vscode . workspace . getConfiguration ( "java" ) . get < boolean > ( "help.shareDiagnostics" ) ;
91101 if ( errors ) {
@@ -97,6 +107,7 @@ export class LogWatcher {
97107 timestamp : e . timestamp ! . toString ( )
98108 } ) : sendInfo ( "" , {
99109 name : "jdtls-error-in-crashed-session" ,
110+ error : redact ( e . message ) ,
100111 timestamp : e . timestamp ! . toString ( )
101112 } ) ;
102113 } )
0 commit comments