@@ -18,6 +18,12 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
18
18
private readonly MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
19
19
// eslint-disable-next-line @typescript-eslint/naming-convention
20
20
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
+ }
21
27
22
28
constructor (
23
29
public readonly name : string ,
@@ -61,13 +67,19 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
61
67
}
62
68
63
69
private getLogFilePath ( ) : string {
70
+ // If we already have a path, reuse it
71
+ if ( RotatingLogChannel . currentLogPath ) {
72
+ return RotatingLogChannel . currentLogPath
73
+ }
74
+
64
75
const logDir = this . extensionContext . storageUri ?. fsPath
65
76
if ( ! logDir ) {
66
77
throw new Error ( 'No storage URI available' )
67
78
}
68
79
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
71
83
}
72
84
73
85
private async rotateLog ( ) : Promise < void > {
@@ -77,15 +89,22 @@ export class RotatingLogChannel implements vscode.LogOutputChannel {
77
89
this . fileStream . end ( )
78
90
}
79
91
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' } )
83
102
this . currentFileSize = 0
84
103
85
104
// Clean up old files
86
105
await this . cleanupOldLogs ( )
87
106
88
- this . logger . info ( `Created new log file: ${ newLogPath } ` )
107
+ this . logger . info ( `Created new log file: ${ RotatingLogChannel . currentLogPath } ` )
89
108
} catch ( err ) {
90
109
this . logger . error ( `Failed to rotate log file: ${ err } ` )
91
110
}
0 commit comments