3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import * as path from 'path'
7
6
import * as vscode from 'vscode'
8
- import * as nls from 'vscode-nls'
9
7
import { Logger , LogLevel , getLogger } from '.'
10
8
import { setLogger } from './logger'
11
9
import { logOutputChannel } from './outputChannel'
12
10
import { WinstonToolkitLogger } from './winstonToolkitLogger'
13
- import { waitUntil } from '../utilities/timeoutUtils'
14
- import { cleanLogFiles } from './util'
15
11
import { Settings } from '../settings'
16
12
import { Logging } from './commands'
17
13
import { resolvePath } from '../utilities/pathUtils'
18
14
import { isWeb } from '../../common/webUtils'
19
15
import { fsCommon } from '../../srcShared/fs'
20
16
21
- const localize = nls . loadMessageBundle ( )
22
-
23
17
const defaultLogLevel : LogLevel = 'info'
24
18
25
19
/**
@@ -32,15 +26,13 @@ export async function activate(
32
26
const chan = logOutputChannel
33
27
const settings = Settings . instance . getSection ( 'aws' )
34
28
const devLogfile = settings . get ( 'dev.logfile' , '' )
35
- const logUri = devLogfile
36
- ? vscode . Uri . file ( resolvePath ( devLogfile ) )
37
- : vscode . Uri . joinPath ( extensionContext . logUri , makeLogFilename ( ) )
29
+ const logUri = devLogfile ? vscode . Uri . file ( resolvePath ( devLogfile ) ) : undefined
38
30
39
31
await fsCommon . mkdir ( extensionContext . logUri )
40
32
41
33
const mainLogger = makeLogger (
42
34
{
43
- logPaths : [ logUri ] ,
35
+ logPaths : logUri ? [ logUri ] : undefined ,
44
36
outputChannels : [ chan ] ,
45
37
useConsoleLog : isWeb ( ) ,
46
38
} ,
@@ -54,7 +46,7 @@ export async function activate(
54
46
setLogger (
55
47
makeLogger (
56
48
{
57
- logPaths : [ logUri ] ,
49
+ logPaths : logUri ? [ logUri ] : undefined ,
58
50
outputChannels : [ outputChannel , chan ] ,
59
51
} ,
60
52
extensionContext . subscriptions
@@ -79,18 +71,6 @@ export async function activate(
79
71
80
72
const commands = new Logging ( logUri , mainLogger )
81
73
extensionContext . subscriptions . push ( ...Object . values ( Logging . declared ) . map ( c => c . register ( commands ) ) )
82
-
83
- createLogWatcher ( logUri )
84
- . then ( sub => {
85
- extensionContext . subscriptions . push ( sub )
86
- } )
87
- . catch ( err => {
88
- getLogger ( ) . warn ( 'Failed to start log file watcher: %s' , err )
89
- } )
90
-
91
- cleanLogFiles ( path . dirname ( logUri . fsPath ) ) . catch ( err => {
92
- getLogger ( ) . warn ( 'Failed to clean-up old logs: %s' , err )
93
- } )
94
74
}
95
75
96
76
/**
@@ -149,60 +129,3 @@ function getLogLevel(): LogLevel {
149
129
const configuration = Settings . instance . getSection ( 'aws' )
150
130
return configuration . get ( 'logLevel' , defaultLogLevel )
151
131
}
152
-
153
- /**
154
- * Creates a name for the toolkit's logfile.
155
- * Essentially an ISO string, but in the local timezone and without the trailing "Z"
156
- * @returns Log filename
157
- */
158
- function makeLogFilename ( ) : string {
159
- const now = new Date ( )
160
- // local to machine: use getMonth/Date instead of UTC equivalent
161
- // month is zero-terminated: offset by 1
162
- const m = ( now . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , '0' )
163
- const d = now . getDate ( ) . toString ( ) . padStart ( 2 , '0' )
164
- const h = now . getHours ( ) . toString ( ) . padStart ( 2 , '0' )
165
- const mn = now . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' )
166
- const s = now . getSeconds ( ) . toString ( ) . padStart ( 2 , '0' )
167
- const dt = `${ now . getFullYear ( ) } ${ m } ${ d } T${ h } ${ mn } ${ s } `
168
-
169
- return `aws_toolkit_${ dt } .log`
170
- }
171
-
172
- /**
173
- * Watches for renames on the log file and notifies the user.
174
- */
175
- async function createLogWatcher ( logFile : vscode . Uri ) : Promise < vscode . Disposable > {
176
- if ( isWeb ( ) ) {
177
- getLogger ( ) . debug ( `Not watching log file since we are in Browser.` )
178
- return { dispose : ( ) => { } }
179
- }
180
-
181
- const exists = await waitUntil ( ( ) => fsCommon . existsFile ( logFile ) , { interval : 1000 , timeout : 60000 } )
182
-
183
- if ( ! exists ) {
184
- getLogger ( ) . warn ( `Log file ${ logFile . path } does not exist!` )
185
- return { dispose : ( ) => { } }
186
- }
187
-
188
- let checking = false
189
- // TODO: fs.watch() has many problems, consider instead:
190
- // - https://github.com/paulmillr/chokidar
191
- // - https://www.npmjs.com/package/fb-watchman
192
- const fs = await import ( 'fs' )
193
- const watcher = fs . watch ( logFile . fsPath , async eventType => {
194
- if ( checking || eventType !== 'rename' ) {
195
- return
196
- }
197
- checking = true
198
- if ( ! ( await fsCommon . existsFile ( logFile ) ) ) {
199
- await vscode . window . showWarningMessage (
200
- localize ( 'AWS.log.logFileMove' , 'The log file for this session has been moved or deleted.' )
201
- )
202
- watcher . close ( )
203
- }
204
- checking = false
205
- } )
206
-
207
- return { dispose : ( ) => watcher . close ( ) }
208
- }
0 commit comments