@@ -1581,15 +1581,15 @@ describe('e2e', function () {
15811581 await shell . waitForPrompt ( ) ;
15821582 shell . assertContainsOutput ( 'Ignoring config option "logLocation"' ) ;
15831583 shell . assertContainsOutput (
1584- 'must be a valid absolute path or empty '
1584+ 'must be a valid absolute path or undefined '
15851585 ) ;
15861586
15871587 expect (
15881588 await shell . executeLine (
15891589 'config.set("logLocation", "[123123123123]")'
15901590 )
15911591 ) . contains (
1592- 'Cannot set option "logLocation": logLocation must be a valid absolute path or empty '
1592+ 'Cannot set option "logLocation": logLocation must be a valid absolute path or undefined '
15931593 ) ;
15941594 } ) ;
15951595
@@ -1722,10 +1722,10 @@ describe('e2e', function () {
17221722 } ) ;
17231723 } ) ;
17241724
1725- describe ( 'with custom log retention days ' , function ( ) {
1725+ describe ( 'with logRetentionDays ' , function ( ) {
17261726 const customLogDir = useTmpdir ( ) ;
17271727
1728- it ( 'should delete older files according to the setting ' , async function ( ) {
1728+ it ( 'should delete older files older than logRetentionDays ' , async function ( ) {
17291729 const paths : string [ ] = [ ] ;
17301730 const today = Math . floor ( Date . now ( ) / 1000 ) ;
17311731 const tenDaysAgo = today - 10 * 24 * 60 * 60 ;
@@ -1776,10 +1776,10 @@ describe('e2e', function () {
17761776 } ) ;
17771777 } ) ;
17781778
1779- describe ( 'with custom log retention max file count ' , function ( ) {
1779+ describe ( 'with logMaxFileCount ' , function ( ) {
17801780 const customLogDir = useTmpdir ( ) ;
17811781
1782- it ( 'should delete files once it is above the max file count limit ' , async function ( ) {
1782+ it ( 'should delete files once it is above logMaxFileCount ' , async function ( ) {
17831783 const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
17841784 await fs . writeFile (
17851785 globalConfig ,
@@ -1825,6 +1825,57 @@ describe('e2e', function () {
18251825 } ) ;
18261826 } ) ;
18271827
1828+ describe ( 'with logRetentionGB' , function ( ) {
1829+ const customLogDir = useTmpdir ( ) ;
1830+
1831+ it ( 'should delete files once it is above logRetentionGB' , async function ( ) {
1832+ const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1833+ await fs . writeFile (
1834+ globalConfig ,
1835+ // Set logRetentionGB to 4 MB and we will create prior 10 log files, 1 MB each
1836+ `mongosh:\n logLocation: ${ JSON . stringify (
1837+ customLogDir . path
1838+ ) } \n logRetentionGB: ${ 4 / 1024 } `
1839+ ) ;
1840+ const paths : string [ ] = [ ] ;
1841+ const offset = Math . floor ( Date . now ( ) / 1000 ) ;
1842+
1843+ // Create 10 log files, around 1 mb each
1844+ for ( let i = 9 ; i >= 0 ; i -- ) {
1845+ const filename = path . join (
1846+ customLogDir . path ,
1847+ ObjectId . createFromTime ( offset - i ) . toHexString ( ) + '_log'
1848+ ) ;
1849+ await fs . writeFile ( filename , '0' . repeat ( 1024 * 1024 ) ) ;
1850+ paths . push ( filename ) ;
1851+ }
1852+
1853+ // All 10 existing log files exist.
1854+ expect ( await getFilesState ( paths ) ) . to . equal ( '1111111111' ) ;
1855+ shell = this . startTestShell ( {
1856+ args : [ '--nodb' ] ,
1857+ env,
1858+ globalConfigPath : globalConfig ,
1859+ forceTerminal : true ,
1860+ } ) ;
1861+
1862+ await shell . waitForPrompt ( ) ;
1863+
1864+ // Add the newly created log to the file list.
1865+ paths . push (
1866+ path . join ( customLogDir . path , `${ shell . logId as string } _log` )
1867+ ) ;
1868+
1869+ expect (
1870+ await shell . executeLine ( 'config.get("logRetentionGB")' )
1871+ ) . contains ( `${ 4 / 1024 } ` ) ;
1872+
1873+ // Expect 6 files to be deleted and 4 to remain
1874+ // (including the new log file which should be <1 MB)
1875+ expect ( await getFilesState ( paths ) ) . to . equal ( '00000001111' ) ;
1876+ } ) ;
1877+ } ) ;
1878+
18281879 it ( 'creates a log file that keeps track of session events' , async function ( ) {
18291880 expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
18301881 const log = await readLogFile ( ) ;
0 commit comments