@@ -8,12 +8,16 @@ import { URI } from 'vs/base/common/uri';
88import { IFileService } from 'vs/platform/files/common/files' ;
99import { Queue } from 'vs/base/common/async' ;
1010import { VSBuffer } from 'vs/base/common/buffer' ;
11+ import { dirname , joinPath , basename } from 'vs/base/common/resources' ;
12+
13+ const MAX_FILE_SIZE = 1024 * 1024 * 5 ;
1114
1215export class FileLogService extends AbstractLogService implements ILogService {
1316
1417 _serviceBrand : undefined ;
1518
1619 private readonly queue : Queue < void > ;
20+ private backupIndex : number = 1 ;
1721
1822 constructor (
1923 private readonly name : string ,
@@ -81,6 +85,10 @@ export class FileLogService extends AbstractLogService implements ILogService {
8185 private _log ( level : LogLevel , message : string ) : void {
8286 this . queue . queue ( async ( ) => {
8387 let content = await this . loadContent ( ) ;
88+ if ( content . length > MAX_FILE_SIZE ) {
89+ await this . fileService . writeFile ( this . getBackupResource ( ) , VSBuffer . fromString ( content ) ) ;
90+ content = '' ;
91+ }
8492 content += `[${ this . getCurrentTimestamp ( ) } ] [${ this . name } ] [${ this . stringifyLogLevel ( level ) } ] ${ message } \n` ;
8593 await this . fileService . writeFile ( this . resource , VSBuffer . fromString ( content ) ) ;
8694 } ) ;
@@ -93,6 +101,11 @@ export class FileLogService extends AbstractLogService implements ILogService {
93101 return `${ currentTime . getFullYear ( ) } -${ toTwoDigits ( currentTime . getMonth ( ) + 1 ) } -${ toTwoDigits ( currentTime . getDate ( ) ) } ${ toTwoDigits ( currentTime . getHours ( ) ) } :${ toTwoDigits ( currentTime . getMinutes ( ) ) } :${ toTwoDigits ( currentTime . getSeconds ( ) ) } .${ toThreeDigits ( currentTime . getMilliseconds ( ) ) } ` ;
94102 }
95103
104+ private getBackupResource ( ) : URI {
105+ this . backupIndex = this . backupIndex > 5 ? 1 : this . backupIndex ;
106+ return joinPath ( dirname ( this . resource ) , `${ basename ( this . resource ) } _${ this . backupIndex ++ } ` ) ;
107+ }
108+
96109 private async loadContent ( ) : Promise < string > {
97110 try {
98111 const content = await this . fileService . readFile ( this . resource ) ;
0 commit comments