@@ -4,7 +4,8 @@ var exported = {},
4
4
automaticStateManager = require ( './helpers/automaticStateManager' ) ,
5
5
log = require ( '../../../api/utils/log.js' ) ( 'logger:api' ) ,
6
6
{ validateRead } = require ( '../../../api/utils/rights.js' ) ;
7
-
7
+ const JOB = require ( '../../../api/parts/jobs' ) ;
8
+ const MAX_NUMBER_OF_LOG_ENTRIES = 1000 ;
8
9
const FEATURE_NAME = 'logger' ;
9
10
10
11
var RequestLoggerStateEnum = {
@@ -20,6 +21,13 @@ plugins.setConfigs("logger", {
20
21
} ) ;
21
22
22
23
( function ( ) {
24
+ plugins . register ( "/master" , function ( ) {
25
+ setTimeout ( ( ) => {
26
+ JOB . job ( 'logger:clear' , { max : MAX_NUMBER_OF_LOG_ENTRIES } )
27
+ . replace ( )
28
+ . schedule ( "every 5 minutes" ) ;
29
+ } , 10000 ) ;
30
+ } ) ;
23
31
24
32
plugins . register ( "/permissions/features" , function ( ob ) {
25
33
ob . features . push ( FEATURE_NAME ) ;
@@ -345,46 +353,32 @@ plugins.setConfigs("logger", {
345
353
return true ;
346
354
}
347
355
if ( params . qstring . method === 'collection_info' ) {
348
- validateRead ( params , FEATURE_NAME , async function ( parameters ) {
349
- try {
350
- var stats = await common . db . collection ( 'logs' + parameters . app_id ) . aggregate ( [ { $collStats : { storageStats : { } } } ] ) . toArray ( ) ;
351
- common . returnOutput ( parameters , { capped : stats ?. [ 0 ] ?. storageStats ?. capped , max : stats ?. [ 0 ] ?. storageStats ?. max } ) ;
352
- }
353
- catch ( ex ) {
354
- console . log ( "Failed fetching logs collection info: " , ex ) ;
355
- common . returnMessage ( parameters , 400 , 'Error fetching collection info' ) ;
356
- }
356
+ validateRead ( params , FEATURE_NAME , function ( parameters ) {
357
+ common . db . collection ( 'logs' + parameters . app_id ) . stats ( function ( err , stats ) {
358
+ if ( err ) {
359
+ console . log ( "Failed fetching logs collection info" , err ) ;
360
+ return common . returnMessage ( parameters , 400 , 'Error fetching collection info' ) ;
361
+ }
362
+ common . returnOutput ( parameters , stats && { size : stats . size , count : stats . count , max : MAX_NUMBER_OF_LOG_ENTRIES } || { } ) ;
363
+ } ) ;
357
364
} ) ;
358
365
return true ;
359
366
}
360
367
} ) ;
361
368
362
- plugins . register ( "/i/apps/create" , function ( ob ) {
363
- var appId = ob . appId ;
364
- common . db . command ( { "convertToCapped" : 'logs' + appId , size : 10000000 , max : 1000 } , function ( err ) {
365
- if ( err ) {
366
- common . db . createCollection ( 'logs' + appId , { capped : true , size : 10000000 , max : 1000 } , function ( ) { } ) ;
367
- }
368
- } ) ;
369
- } ) ;
370
-
371
369
plugins . register ( "/i/apps/delete" , function ( ob ) {
372
370
var appId = ob . appId ;
373
371
common . db . collection ( 'logs' + appId ) . drop ( function ( ) { } ) ;
374
372
} ) ;
375
373
376
374
plugins . register ( "/i/apps/reset" , function ( ob ) {
377
375
var appId = ob . appId ;
378
- common . db . collection ( 'logs' + appId ) . drop ( function ( ) {
379
- common . db . createCollection ( 'logs' + appId , { capped : true , size : 10000000 , max : 1000 } , function ( ) { } ) ;
380
- } ) ;
376
+ common . db . collection ( 'logs' + appId ) . drop ( function ( ) { } ) ;
381
377
} ) ;
382
378
383
379
plugins . register ( "/i/apps/clear_all" , function ( ob ) {
384
380
var appId = ob . appId ;
385
- common . db . collection ( 'logs' + appId ) . drop ( function ( ) {
386
- common . db . createCollection ( 'logs' + appId , { capped : true , size : 10000000 , max : 1000 } , function ( ) { } ) ;
387
- } ) ;
381
+ common . db . collection ( 'logs' + appId ) . drop ( function ( ) { } ) ;
388
382
} ) ;
389
383
} ( exported ) ) ;
390
384
0 commit comments