@@ -18,6 +18,12 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
1818 private readonly MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
1919 // eslint-disable-next-line @typescript-eslint/naming-convention
2020 private readonly MAX_LOG_FILES = 4
21+ private static currentLogPath : string | undefined
22+
23+ private static generateNewLogPath ( logDir : string ) : string {
24+ const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, '-' ) . replace ( 'T' , '-' ) . replace ( 'Z' , '' )
25+ return path . join ( logDir , `amazonq-lsp-${ timestamp } .log` )
26+ }
2127
2228 constructor (
2329 public readonly name : string ,
@@ -61,13 +67,19 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
6167 }
6268
6369 private getLogFilePath ( ) : string {
70+ // If we already have a path, reuse it
71+ if ( RotatingLogChannel . currentLogPath ) {
72+ return RotatingLogChannel . currentLogPath
73+ }
74+
6475 const logDir = this . extensionContext . storageUri ?. fsPath
6576 if ( ! logDir ) {
6677 throw new Error ( 'No storage URI available' )
6778 }
6879
69- const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, '-' ) . replace ( 'T' , '-' ) . replace ( 'Z' , '' )
70- return path . join ( logDir , `amazonq-lsp-${ timestamp } .log` )
80+ // Generate initial path
81+ RotatingLogChannel . currentLogPath = RotatingLogChannel . generateNewLogPath ( logDir )
82+ return RotatingLogChannel . currentLogPath
7183 }
7284
7385 private async rotateLog ( ) : Promise < void > {
@@ -77,15 +89,22 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
7789 this . fileStream . end ( )
7890 }
7991
80- // Create new log file
81- const newLogPath = this . getLogFilePath ( )
82- this . fileStream = fs . createWriteStream ( newLogPath , { flags : 'a' } )
92+ const logDir = this . extensionContext . storageUri ?. fsPath
93+ if ( ! logDir ) {
94+ throw new Error ( 'No storage URI available' )
95+ }
96+
97+ // Generate new path directly
98+ RotatingLogChannel . currentLogPath = RotatingLogChannel . generateNewLogPath ( logDir )
99+
100+ // Create new log file with new path
101+ this . fileStream = fs . createWriteStream ( RotatingLogChannel . currentLogPath , { flags : 'a' } )
83102 this . currentFileSize = 0
84103
85104 // Clean up old files
86105 await this . cleanupOldLogs ( )
87106
88- this . logger . info ( `Created new log file: ${ newLogPath } ` )
107+ this . logger . info ( `Created new log file: ${ RotatingLogChannel . currentLogPath } ` )
89108 } catch ( err ) {
90109 this . logger . error ( `Failed to rotate log file: ${ err } ` )
91110 }
0 commit comments