@@ -1356,7 +1356,7 @@ describe('e2e', function () {
13561356 let logBasePath : string ;
13571357 let historyPath : string ;
13581358 let readConfig : ( ) => Promise < any > ;
1359- let readLogfile : ( ) => Promise < LogEntry [ ] > ;
1359+ let readLogFile : ( ) => Promise < LogEntry [ ] > ;
13601360 let startTestShell : ( ...extraArgs : string [ ] ) => Promise < TestShell > ;
13611361
13621362 beforeEach ( function ( ) {
@@ -1393,7 +1393,7 @@ describe('e2e', function () {
13931393 }
13941394 readConfig = async ( ) =>
13951395 EJSON . parse ( await fs . readFile ( configPath , 'utf8' ) ) ;
1396- readLogfile = async ( ) => {
1396+ readLogFile = async ( ) => {
13971397 if ( ! shell . logId ) {
13981398 throw new Error ( 'Shell does not have a logId associated with it' ) ;
13991399 }
@@ -1508,7 +1508,7 @@ describe('e2e', function () {
15081508 } ) ;
15091509
15101510 describe ( 'log file' , function ( ) {
1511- it ( 'does not create a log if global config has disableLogging' , async function ( ) {
1511+ it ( 'does not get created if global config has disableLogging' , async function ( ) {
15121512 const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
15131513 await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: true' ) ;
15141514 shell = this . startTestShell ( {
@@ -1529,9 +1529,38 @@ describe('e2e', function () {
15291529 expect ( shell . logId ) . equals ( null ) ;
15301530 } ) ;
15311531
1532+ it ( 'gets created if global config has disableLogging set to false' , async function ( ) {
1533+ const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1534+ await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: false' ) ;
1535+ shell = this . startTestShell ( {
1536+ args : [ '--nodb' ] ,
1537+ env : {
1538+ ...env ,
1539+ MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING : globalConfig ,
1540+ } ,
1541+ forceTerminal : true ,
1542+ } ) ;
1543+ await shell . waitForPrompt ( ) ;
1544+ expect (
1545+ await shell . executeLine ( 'config.get("disableLogging")' )
1546+ ) . to . include ( 'false' ) ;
1547+ shell . assertNoErrors ( ) ;
1548+
1549+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1550+ expect ( shell . logId ) . not . equal ( null ) ;
1551+
1552+ const log = await readLogFile ( ) ;
1553+ expect (
1554+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1555+ log . filter (
1556+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1557+ )
1558+ ) . to . have . lengthOf ( 1 ) ;
1559+ } ) ;
1560+
15321561 it ( 'creates a log file that keeps track of session events' , async function ( ) {
15331562 expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1534- const log = await readLogfile ( ) ;
1563+ const log = await readLogFile ( ) ;
15351564 expect (
15361565 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
15371566 log . filter (
@@ -1540,9 +1569,9 @@ describe('e2e', function () {
15401569 ) . to . have . lengthOf ( 1 ) ;
15411570 } ) ;
15421571
1543- it ( 'does not write to the log file after disableLogging is set to true' , async function ( ) {
1572+ it ( 'does not write to the log after disableLogging is set to true' , async function ( ) {
15441573 expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1545- const log = await readLogfile ( ) ;
1574+ const log = await readLogFile ( ) ;
15461575 expect (
15471576 log . filter (
15481577 ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
@@ -1552,7 +1581,7 @@ describe('e2e', function () {
15521581 await shell . executeLine ( `config.set("disableLogging", true)` ) ;
15531582 expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
15541583
1555- const logAfterDisabling = await readLogfile ( ) ;
1584+ const logAfterDisabling = await readLogFile ( ) ;
15561585 expect (
15571586 logAfterDisabling . filter (
15581587 ( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
@@ -1565,6 +1594,43 @@ describe('e2e', function () {
15651594 ) . to . have . lengthOf ( 1 ) ;
15661595 } ) ;
15671596
1597+ it ( 'starts writing to a new log from the point where disableLogging is set to false' , async function ( ) {
1598+ await shell . executeLine ( `config.set("disableLogging", true)` ) ;
1599+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1600+ const log = await readLogFile ( ) ;
1601+ const oldLogId = shell . logId ;
1602+ expect ( oldLogId ) . not . null ;
1603+
1604+ expect (
1605+ log . filter (
1606+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1607+ )
1608+ ) . to . have . lengthOf ( 0 ) ;
1609+
1610+ await shell . executeLine ( `config.set("disableLogging", false)` ) ;
1611+
1612+ expect (
1613+ await shell . executeLine ( 'config.get("disableLogging")' )
1614+ ) . to . include ( 'false' ) ;
1615+
1616+ expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
1617+
1618+ const newLogId = shell . logId ;
1619+ expect ( newLogId ) . not . null ;
1620+ expect ( oldLogId ) . not . equal ( newLogId ) ;
1621+ const logsAfterEnabling = await readLogFile ( ) ;
1622+ expect (
1623+ logsAfterEnabling . filter (
1624+ ( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
1625+ )
1626+ ) . to . have . lengthOf ( 1 ) ;
1627+ expect (
1628+ logsAfterEnabling . filter (
1629+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1630+ )
1631+ ) . to . have . lengthOf ( 0 ) ;
1632+ } ) ;
1633+
15681634 it ( 'includes information about the driver version' , async function ( ) {
15691635 const connectionString = await testServer . connectionString ( ) ;
15701636 expect (
@@ -1573,7 +1639,7 @@ describe('e2e', function () {
15731639 )
15741640 ) . to . include ( 'test' ) ;
15751641 await eventually ( async ( ) => {
1576- const log = await readLogfile ( ) ;
1642+ const log = await readLogFile ( ) ;
15771643 expect (
15781644 log . filter (
15791645 ( logEntry ) => typeof logEntry . attr ?. driver ?. version === 'string'
0 commit comments