@@ -257,50 +257,30 @@ export class CliRepl implements MongoshIOProvider {
257
257
) ;
258
258
}
259
259
260
- /** Setup analytics, logging and telemetry. */
261
- private async startLoggingAndTelemetry ( ) {
262
- // Read the global config with log settings, e.g. logLocation, disableLogging
263
- const disableLogging = this . getConfig ( 'disableLogging' ) ;
264
- if ( ! disableLogging ) {
265
- await this . logManager . cleanupOldLogFiles ( ) ;
266
- markTime ( TimingCategories . Logging , 'cleaned up log files' ) ;
267
-
268
- const logger = await this . logManager . createLogWriter ( ) ;
269
- const { quiet } = CliRepl . getFileAndEvalInfo ( this . cliOptions ) ;
270
- if ( ! quiet ) {
271
- this . output . write ( `Current Mongosh Log ID:\t${ logger . logId } \n` ) ;
272
- }
273
-
274
- this . logWriter = logger ;
275
- setupMongoLogWriter ( logger ) ;
276
- markTime ( TimingCategories . Logging , 'instantiated log writer' ) ;
277
- this . bus . emit ( 'mongosh:log-initialized' ) ;
278
- logger . info ( 'MONGOSH' , mongoLogId ( 1_000_000_000 ) , 'log' , 'Starting log' , {
279
- execPath : process . execPath ,
280
- envInfo : redactSensitiveData ( this . getLoggedEnvironmentVariables ( ) ) ,
281
- ...( await buildInfo ( ) ) ,
282
- } ) ;
283
-
284
- markTime ( TimingCategories . Logging , 'logged initial message' ) ;
285
- }
286
-
287
- markTime ( TimingCategories . Telemetry , 'completed telemetry setup' ) ;
288
-
289
- // Create analytics instance
290
- let analyticsSetupError : Error | null = null ;
291
- try {
292
- await this . setupAnalytics ( ) ;
293
- } catch ( err : unknown ) {
294
- // Need to delay emitting the error on the bus so that logging is in place
295
- // as well
296
- analyticsSetupError = err as Error ;
260
+ /** Setup log writer and start logging. */
261
+ private async startLogging ( ) {
262
+ await this . logManager . cleanupOldLogFiles ( ) ;
263
+ markTime ( TimingCategories . Logging , 'cleaned up log files' ) ;
264
+ const logger = await this . logManager . createLogWriter ( ) ;
265
+ const { quiet } = CliRepl . getFileAndEvalInfo ( this . cliOptions ) ;
266
+ if ( ! quiet ) {
267
+ this . output . write ( `Current Mongosh Log ID:\t${ logger . logId } \n` ) ;
297
268
}
298
269
299
- markTime ( TimingCategories . Telemetry , 'created analytics instance' ) ;
300
-
301
- if ( analyticsSetupError ) {
302
- this . bus . emit ( 'mongosh:error' , analyticsSetupError , 'analytics' ) ;
303
- }
270
+ this . logWriter = logger ;
271
+ this . logWriter = logger ;
272
+ setupMongoLogWriter ( logger ) ;
273
+ this . logWriter = logger ;
274
+ setupMongoLogWriter ( logger ) ;
275
+ markTime ( TimingCategories . Logging , 'instantiated log writer' ) ;
276
+ setupMongoLogWriter ( logger ) ;
277
+ this . bus . emit ( 'mongosh:log-initialized' ) ;
278
+ logger . info ( 'MONGOSH' , mongoLogId ( 1_000_000_000 ) , 'log' , 'Starting log' , {
279
+ execPath : process . execPath ,
280
+ envInfo : redactSensitiveData ( this . getLoggedEnvironmentVariables ( ) ) ,
281
+ ...( await buildInfo ( ) ) ,
282
+ } ) ;
283
+ markTime ( TimingCategories . Logging , 'logged initial message' ) ;
304
284
}
305
285
306
286
/**
@@ -355,14 +335,20 @@ export class CliRepl implements MongoshIOProvider {
355
335
}
356
336
markTime ( TimingCategories . REPLInstantiation , 'ensured shell homedir' ) ;
357
337
358
- // Setup telemetry
338
+ let analyticsSetupError : Error | null = null ;
339
+ try {
340
+ await this . setupAnalytics ( ) ;
341
+ } catch ( err : unknown ) {
342
+ // Need to delay emitting the error on the bus so that logging is in place
343
+ // as well
344
+ analyticsSetupError = err as Error ;
345
+ }
346
+
347
+ markTime ( TimingCategories . Telemetry , 'created analytics instance' ) ;
348
+
359
349
setupLoggerAndTelemetry (
360
350
this . bus ,
361
351
this . toggleableAnalytics ,
362
- {
363
- userId : this . getConfig ( 'userId' ) ,
364
- telemetryAnonymousId : this . getConfig ( 'telemetryAnonymousId' ) ,
365
- } ,
366
352
{
367
353
platform : process . platform ,
368
354
arch : process . arch ,
@@ -371,8 +357,13 @@ export class CliRepl implements MongoshIOProvider {
371
357
} ,
372
358
version
373
359
) ;
360
+ markTime ( TimingCategories . Telemetry , 'completed telemetry setup' ) ;
361
+
362
+ if ( analyticsSetupError ) {
363
+ this . bus . emit ( 'mongosh:error' , analyticsSetupError , 'analytics' ) ;
364
+ }
374
365
375
- // Get configuration
366
+ // Read local and global configuration
376
367
try {
377
368
this . config = await this . configDirectory . generateOrReadConfig (
378
369
this . config
@@ -384,7 +375,10 @@ export class CliRepl implements MongoshIOProvider {
384
375
this . globalConfig = await this . loadGlobalConfigFile ( ) ;
385
376
markTime ( TimingCategories . UserConfigLoading , 'read global config files' ) ;
386
377
387
- await this . startLoggingAndTelemetry ( ) ;
378
+ const disableLogging = this . getConfig ( 'disableLogging' ) ;
379
+ if ( disableLogging !== true ) {
380
+ await this . startLogging ( ) ;
381
+ }
388
382
389
383
// Needs to happen after loading the mongosh config file(s)
390
384
void this . fetchMongoshUpdateUrl ( ) ;
@@ -543,6 +537,7 @@ export class CliRepl implements MongoshIOProvider {
543
537
this . bus . emit ( 'mongosh:start-mongosh-repl' , { version } ) ;
544
538
markTime ( TimingCategories . REPLInstantiation , 'starting repl' ) ;
545
539
await this . mongoshRepl . startRepl ( initialized ) ;
540
+
546
541
this . bus . emit ( 'mongosh:start-session' , {
547
542
isInteractive : true ,
548
543
jsContext : this . mongoshRepl . jsContext ( ) ,
@@ -647,7 +642,7 @@ export class CliRepl implements MongoshIOProvider {
647
642
files : string [ ] ,
648
643
evalScripts : string [ ]
649
644
) : Promise < number > {
650
- let lastEvalResult : any ;
645
+ let lastEvalResult : unknown ;
651
646
let exitCode = 0 ;
652
647
try {
653
648
markTime ( TimingCategories . Eval , 'start eval scripts' ) ;
@@ -1305,7 +1300,8 @@ export class CliRepl implements MongoshIOProvider {
1305
1300
}
1306
1301
1307
1302
async getMoreRecentMongoshVersion ( ) : Promise < string | null > {
1308
- const { version } = require ( '../package.json' ) ;
1303
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
1304
+ const { version } : { version : string } = require ( '../package.json' ) ;
1309
1305
return await this . updateNotificationManager . getLatestVersionIfMoreRecent (
1310
1306
process . env
1311
1307
. MONGOSH_ASSUME_DIFFERENT_VERSION_FOR_UPDATE_NOTIFICATION_TEST ||
0 commit comments