@@ -22,17 +22,13 @@ export class Logger {
2222 private logFilePath : string ;
2323
2424 public logBasePath : string ;
25+ public logSessionPath : string ;
26+ public MinimumLogLevel : LogLevel = LogLevel . Normal ;
2527
26- constructor ( readonly MinimumLogLevel : LogLevel = LogLevel . Normal ) {
28+ constructor ( ) {
2729 this . logChannel = vscode . window . createOutputChannel ( "PowerShell Extension Logs" ) ;
2830
29- this . logBasePath =
30- path . resolve (
31- __dirname ,
32- "../logs" ,
33- `${ Math . floor ( Date . now ( ) / 1000 ) } -${ vscode . env . sessionId } ` ) ;
34- this . logFilePath = this . getLogFilePath ( "vscode-powershell" ) ;
35-
31+ this . logBasePath = path . resolve ( __dirname , "../logs" ) ;
3632 utils . ensurePathExists ( this . logBasePath ) ;
3733
3834 this . commands = [
@@ -47,7 +43,7 @@ export class Logger {
4743 }
4844
4945 public getLogFilePath ( baseName : string ) : string {
50- return path . resolve ( this . logBasePath , `${ baseName } .log` ) ;
46+ return path . resolve ( this . logSessionPath , `${ baseName } .log` ) ;
5147 }
5248
5349 public writeAtLevel ( logLevel : LogLevel , message : string , ...additionalMessages : string [ ] ) {
@@ -99,6 +95,29 @@ export class Logger {
9995 } ) ;
10096 }
10197
98+ public startNewLog ( minimumLogLevel : string = "Normal" ) {
99+ this . MinimumLogLevel = this . logLevelNameToValue ( minimumLogLevel . trim ( ) ) ;
100+
101+ this . logSessionPath =
102+ path . resolve (
103+ this . logBasePath ,
104+ `${ Math . floor ( Date . now ( ) / 1000 ) } -${ vscode . env . sessionId } ` ) ;
105+
106+ this . logFilePath = this . getLogFilePath ( "vscode-powershell" ) ;
107+
108+ utils . ensurePathExists ( this . logSessionPath ) ;
109+ }
110+
111+ private logLevelNameToValue ( logLevelName : string ) : LogLevel {
112+ switch ( logLevelName . toLowerCase ( ) ) {
113+ case "normal" : return LogLevel . Normal ;
114+ case "verbose" : return LogLevel . Verbose ;
115+ case "warning" : return LogLevel . Warning ;
116+ case "error" : return LogLevel . Error ;
117+ default : return LogLevel . Normal ;
118+ }
119+ }
120+
102121 public dispose ( ) {
103122 this . commands . forEach ( ( command ) => { command . dispose ( ) } ) ;
104123 this . logChannel . dispose ( ) ;
@@ -109,12 +128,14 @@ export class Logger {
109128 }
110129
111130 private openLogFolder ( ) {
112- // Open the folder in VS Code since there isn't an easy way to
113- // open the folder in the platform's file browser
114- vscode . commands . executeCommand (
115- 'vscode.openFolder' ,
116- vscode . Uri . file ( this . logBasePath ) ,
117- true ) ;
131+ if ( this . logSessionPath ) {
132+ // Open the folder in VS Code since there isn't an easy way to
133+ // open the folder in the platform's file browser
134+ vscode . commands . executeCommand (
135+ 'vscode.openFolder' ,
136+ vscode . Uri . file ( this . logSessionPath ) ,
137+ true ) ;
138+ }
118139 }
119140}
120141
0 commit comments