@ -12,8 +12,40 @@ const logger = new Logger('Meteor', {
}
} ) ;
let Log _Trace _Methods ;
let Log _Trace _Subscriptions ;
RocketChat . settings . get ( 'Log_Trace_Methods' , ( key , value ) => Log _Trace _Methods = value ) ;
RocketChat . settings . get ( 'Log_Trace_Subscriptions' , ( key , value ) => Log _Trace _Subscriptions = value ) ;
let Log _Trace _Methods _Filter ;
let Log _Trace _Subscriptions _Filter ;
RocketChat . settings . get ( 'Log_Trace_Methods_Filter' , ( key , value ) => Log _Trace _Methods _Filter = value ? new RegExp ( value ) : undefined ) ;
RocketChat . settings . get ( 'Log_Trace_Subscriptions_Filter' , ( key , value ) => Log _Trace _Subscriptions _Filter = value ? new RegExp ( value ) : undefined ) ;
const traceConnection = ( enable , filter , prefix , name , connection , userId ) => {
if ( ! enable ) {
return ;
}
if ( filter && ! filter . test ( name ) ) {
return ;
}
if ( connection ) {
console . log ( name , {
id : connection . id ,
clientAddress : connection . clientAddress ,
httpHeaders : connection . httpHeaders ,
userId
} ) ;
} else {
console . log ( name , 'no-connection' ) ;
}
} ;
const wrapMethods = function ( name , originalHandler , methodsMap ) {
methodsMap [ name ] = function ( ) {
traceConnection ( Log _Trace _Methods , Log _Trace _Methods _Filter , 'method' , name , this . connection , this . userId ) ;
const end = RocketChat . metrics . meteorMethods . startTimer ( { method : name } ) ;
const args = name === 'ufsWrite' ? Array . prototype . slice . call ( arguments , 1 ) : arguments ;
logger . method ( name , '-> userId:' , Meteor . userId ( ) , ', arguments: ' , args ) ;
@ -37,6 +69,7 @@ const originalMeteorPublish = Meteor.publish;
Meteor . publish = function ( name , func ) {
return originalMeteorPublish ( name , function ( ) {
traceConnection ( Log _Trace _Subscriptions , Log _Trace _Subscriptions _Filter , 'subscription' , name , this . connection , this . userId ) ;
logger . publish ( name , '-> userId:' , this . userId , ', arguments: ' , arguments ) ;
const end = RocketChat . metrics . meteorSubscriptions . startTimer ( { subscription : name } ) ;