@@ -22,19 +22,11 @@ export class Logger {
22
22
private logFilePath : string ;
23
23
24
24
public logBasePath : string ;
25
+ public MinimumLogLevel : LogLevel = LogLevel . Normal ;
25
26
26
- constructor ( readonly MinimumLogLevel : LogLevel = LogLevel . Normal ) {
27
+ constructor ( ) {
27
28
this . logChannel = vscode . window . createOutputChannel ( "PowerShell Extension Logs" ) ;
28
29
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
-
36
- utils . ensurePathExists ( this . logBasePath ) ;
37
-
38
30
this . commands = [
39
31
vscode . commands . registerCommand (
40
32
'PowerShell.ShowLogs' ,
@@ -99,6 +91,30 @@ export class Logger {
99
91
} ) ;
100
92
}
101
93
94
+ public startNewLog ( minimumLogLevel : string = "Normal" ) {
95
+ this . MinimumLogLevel = this . logLevelNameToValue ( minimumLogLevel . trim ( ) ) ;
96
+
97
+ this . logBasePath =
98
+ path . resolve (
99
+ __dirname ,
100
+ "../logs" ,
101
+ `${ Math . floor ( Date . now ( ) / 1000 ) } -${ vscode . env . sessionId } ` ) ;
102
+
103
+ this . logFilePath = this . getLogFilePath ( "vscode-powershell" ) ;
104
+
105
+ utils . ensurePathExists ( this . logBasePath ) ;
106
+ }
107
+
108
+ private logLevelNameToValue ( logLevelName : string ) : LogLevel {
109
+ switch ( logLevelName . toLowerCase ( ) ) {
110
+ case "normal" : return LogLevel . Normal ;
111
+ case "verbose" : return LogLevel . Verbose ;
112
+ case "warning" : return LogLevel . Warning ;
113
+ case "error" : return LogLevel . Error ;
114
+ default : return LogLevel . Normal ;
115
+ }
116
+ }
117
+
102
118
public dispose ( ) {
103
119
this . commands . forEach ( ( command ) => { command . dispose ( ) } ) ;
104
120
this . logChannel . dispose ( ) ;
@@ -109,12 +125,14 @@ export class Logger {
109
125
}
110
126
111
127
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 ) ;
128
+ if ( this . logBasePath ) {
129
+ // Open the folder in VS Code since there isn't an easy way to
130
+ // open the folder in the platform's file browser
131
+ vscode . commands . executeCommand (
132
+ 'vscode.openFolder' ,
133
+ vscode . Uri . file ( this . logBasePath ) ,
134
+ true ) ;
135
+ }
118
136
}
119
137
}
120
138
0 commit comments