@@ -22,17 +22,13 @@ export class Logger {
22
22
private logFilePath : string ;
23
23
24
24
public logBasePath : string ;
25
+ public logSessionPath : string ;
26
+ public MinimumLogLevel : LogLevel = LogLevel . Normal ;
25
27
26
- constructor ( readonly MinimumLogLevel : LogLevel = LogLevel . Normal ) {
28
+ constructor ( ) {
27
29
this . logChannel = vscode . window . createOutputChannel ( "PowerShell Extension Logs" ) ;
28
30
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" ) ;
36
32
utils . ensurePathExists ( this . logBasePath ) ;
37
33
38
34
this . commands = [
@@ -47,7 +43,7 @@ export class Logger {
47
43
}
48
44
49
45
public getLogFilePath ( baseName : string ) : string {
50
- return path . resolve ( this . logBasePath , `${ baseName } .log` ) ;
46
+ return path . resolve ( this . logSessionPath , `${ baseName } .log` ) ;
51
47
}
52
48
53
49
public writeAtLevel ( logLevel : LogLevel , message : string , ...additionalMessages : string [ ] ) {
@@ -99,6 +95,29 @@ export class Logger {
99
95
} ) ;
100
96
}
101
97
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
+
102
121
public dispose ( ) {
103
122
this . commands . forEach ( ( command ) => { command . dispose ( ) } ) ;
104
123
this . logChannel . dispose ( ) ;
@@ -109,12 +128,14 @@ export class Logger {
109
128
}
110
129
111
130
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
+ }
118
139
}
119
140
}
120
141
0 commit comments