File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,7 @@ describe('CliRepl', function () {
301
301
'browser' ,
302
302
'updateURL' ,
303
303
'disableLogging' ,
304
+ 'logLocation' ,
304
305
] satisfies ( keyof CliUserConfig ) [ ] ) ;
305
306
} ) ;
306
307
@@ -1342,6 +1343,15 @@ describe('CliRepl', function () {
1342
1343
expect ( emitSpy ) . not . calledWith ( 'mongosh:logger-initialized' ) ;
1343
1344
expect ( cliRepl . logWriter ) . is . undefined ;
1344
1345
} ) ;
1346
+
1347
+ it ( 'can set the log location' , async function ( ) {
1348
+ const testPath = './test/path' ;
1349
+ cliRepl . config . logLocation = testPath ;
1350
+ await cliRepl . start ( await testServer . connectionString ( ) , { } ) ;
1351
+
1352
+ expect ( cliRepl . getConfig ( 'logLocation' ) ) . is . true ;
1353
+ expect ( cliRepl . logWriter ?. logFilePath ) . equals ( testPath ) ;
1354
+ } ) ;
1345
1355
} ) ;
1346
1356
1347
1357
context ( 'analytics integration' , function ( ) {
Original file line number Diff line number Diff line change @@ -190,7 +190,8 @@ export class CliRepl implements MongoshIOProvider {
190
190
} ) ;
191
191
192
192
this . logManager = new MongoLogManager ( {
193
- directory : this . shellHomeDirectory . localPath ( '.' ) ,
193
+ directory :
194
+ this . getConfig ( 'logLocation' ) ?? this . shellHomeDirectory . localPath ( '.' ) ,
194
195
retentionDays : 30 ,
195
196
maxLogFileCount : + (
196
197
process . env . MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100
Original file line number Diff line number Diff line change @@ -502,6 +502,7 @@ export class CliUserConfig extends SnippetShellUserConfig {
502
502
browser : undefined | false | string = undefined ;
503
503
updateURL = 'https://downloads.mongodb.com/compass/mongosh.json' ;
504
504
disableLogging = false ;
505
+ logLocation : string | undefined = undefined ;
505
506
}
506
507
507
508
export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
@@ -574,6 +575,15 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
574
575
return `${ key } must be a valid URL or empty` ;
575
576
}
576
577
return null ;
578
+ case 'logLocation' :
579
+ if (
580
+ value !== undefined &&
581
+ typeof value !== 'string' &&
582
+ ! isValidPath ( value )
583
+ ) {
584
+ return `${ key } must be a valid path or empty` ;
585
+ }
586
+ return null ;
577
587
default :
578
588
return super . validate (
579
589
key as keyof SnippetShellUserConfig ,
@@ -619,6 +629,15 @@ function isValidUrl(url: string): boolean {
619
629
return true ; // Currently no overlap between URL-less environments and environments with config options.
620
630
}
621
631
632
+ function isValidPath ( path : unknown ) : boolean {
633
+ const pathRegex = / ^ (?: [ a - z A - Z ] : ) ? (?: [ \\ / ] [ \w . - ] + ) + [ \\ / ] ? $ / ;
634
+
635
+ if ( typeof path === 'string' ) {
636
+ return pathRegex . test ( path ) ;
637
+ }
638
+ return false ;
639
+ }
640
+
622
641
export const TimingCategories = {
623
642
REPLInstantiation : 'REPLInstantiation' ,
624
643
UserConfigLoading : 'UserConfigLoading' ,
You can’t perform that action at this time.
0 commit comments