@@ -1363,7 +1363,7 @@ describe('e2e', function () {
13631363 let logBasePath : string ;
13641364 let historyPath : string ;
13651365 let readConfig : ( ) => Promise < any > ;
1366- let readLogfile : ( ) => Promise < LogEntry [ ] > ;
1366+ let readLogFile : ( ) => Promise < LogEntry [ ] > ;
13671367 let startTestShell : ( ...extraArgs : string [ ] ) => Promise < TestShell > ;
13681368
13691369 beforeEach ( function ( ) {
@@ -1400,7 +1400,7 @@ describe('e2e', function () {
14001400 }
14011401 readConfig = async ( ) =>
14021402 EJSON . parse ( await fs . readFile ( configPath , 'utf8' ) ) ;
1403- readLogfile = async ( ) => {
1403+ readLogFile = async ( ) => {
14041404 if ( ! shell . logId ) {
14051405 throw new Error ( 'Shell does not have a logId associated with it' ) ;
14061406 }
@@ -1515,7 +1515,7 @@ describe('e2e', function () {
15151515 } ) ;
15161516
15171517 describe ( 'log file' , function ( ) {
1518- it ( 'does not create a log if global config has disableLogging' , async function ( ) {
1518+ it ( 'does not get created if global config has disableLogging' , async function ( ) {
15191519 const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
15201520 await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: true' ) ;
15211521 shell = this . startTestShell ( {
@@ -1536,9 +1536,38 @@ describe('e2e', function () {
15361536 expect ( shell . logId ) . equals ( null ) ;
15371537 } ) ;
15381538
1539+ it ( 'gets created if global config has disableLogging set to false' , async function ( ) {
1540+ const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1541+ await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: false' ) ;
1542+ shell = this . startTestShell ( {
1543+ args : [ '--nodb' ] ,
1544+ env : {
1545+ ...env ,
1546+ MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING : globalConfig ,
1547+ } ,
1548+ forceTerminal : true ,
1549+ } ) ;
1550+ await shell . waitForPrompt ( ) ;
1551+ expect (
1552+ await shell . executeLine ( 'config.get("disableLogging")' )
1553+ ) . to . include ( 'false' ) ;
1554+ shell . assertNoErrors ( ) ;
1555+
1556+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1557+ expect ( shell . logId ) . not . equal ( null ) ;
1558+
1559+ const log = await readLogFile ( ) ;
1560+ expect (
1561+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1562+ log . filter (
1563+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1564+ )
1565+ ) . to . have . lengthOf ( 1 ) ;
1566+ } ) ;
1567+
15391568 it ( 'creates a log file that keeps track of session events' , async function ( ) {
15401569 expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1541- const log = await readLogfile ( ) ;
1570+ const log = await readLogFile ( ) ;
15421571 expect (
15431572 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
15441573 log . filter (
@@ -1547,9 +1576,9 @@ describe('e2e', function () {
15471576 ) . to . have . lengthOf ( 1 ) ;
15481577 } ) ;
15491578
1550- it ( 'does not write to the log file after disableLogging is set to true' , async function ( ) {
1579+ it ( 'does not write to the log after disableLogging is set to true' , async function ( ) {
15511580 expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1552- const log = await readLogfile ( ) ;
1581+ const log = await readLogFile ( ) ;
15531582 expect (
15541583 log . filter (
15551584 ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
@@ -1559,7 +1588,7 @@ describe('e2e', function () {
15591588 await shell . executeLine ( `config.set("disableLogging", true)` ) ;
15601589 expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
15611590
1562- const logAfterDisabling = await readLogfile ( ) ;
1591+ const logAfterDisabling = await readLogFile ( ) ;
15631592 expect (
15641593 logAfterDisabling . filter (
15651594 ( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
@@ -1572,6 +1601,43 @@ describe('e2e', function () {
15721601 ) . to . have . lengthOf ( 1 ) ;
15731602 } ) ;
15741603
1604+ it ( 'starts writing to a new log from the point where disableLogging is set to false' , async function ( ) {
1605+ await shell . executeLine ( `config.set("disableLogging", true)` ) ;
1606+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1607+ const log = await readLogFile ( ) ;
1608+ const oldLogId = shell . logId ;
1609+ expect ( oldLogId ) . not . null ;
1610+
1611+ expect (
1612+ log . filter (
1613+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1614+ )
1615+ ) . to . have . lengthOf ( 0 ) ;
1616+
1617+ await shell . executeLine ( `config.set("disableLogging", false)` ) ;
1618+
1619+ expect (
1620+ await shell . executeLine ( 'config.get("disableLogging")' )
1621+ ) . to . include ( 'false' ) ;
1622+
1623+ expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
1624+
1625+ const newLogId = shell . logId ;
1626+ expect ( newLogId ) . not . null ;
1627+ expect ( oldLogId ) . not . equal ( newLogId ) ;
1628+ const logsAfterEnabling = await readLogFile ( ) ;
1629+ expect (
1630+ logsAfterEnabling . filter (
1631+ ( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
1632+ )
1633+ ) . to . have . lengthOf ( 1 ) ;
1634+ expect (
1635+ logsAfterEnabling . filter (
1636+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1637+ )
1638+ ) . to . have . lengthOf ( 0 ) ;
1639+ } ) ;
1640+
15751641 it ( 'includes information about the driver version' , async function ( ) {
15761642 const connectionString = await testServer . connectionString ( ) ;
15771643 expect (
@@ -1580,7 +1646,7 @@ describe('e2e', function () {
15801646 )
15811647 ) . to . include ( 'test' ) ;
15821648 await eventually ( async ( ) => {
1583- const log = await readLogfile ( ) ;
1649+ const log = await readLogFile ( ) ;
15841650 expect (
15851651 log . filter (
15861652 ( logEntry ) => typeof logEntry . attr ?. driver ?. version === 'string'
0 commit comments