Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1570,11 +1570,17 @@
"Loading_more_from_history": "Loading more from history",
"Loading_suggestion": "Loading suggestions",
"Localization": "Localization",
"Log_Exceptions_to_Channel": "Log Exceptions to Channel",
"Log_Exceptions_to_Channel_Description": "A channel that will receive all captured exceptions. Leave empty to ignore exceptions.",
"Log_Exceptions_to_Channel": "Log Exceptions to Channel",
"Log_File": "Show File and Line",
"Log_Level": "Log Level",
"Log_Package": "Show Package",
"Log_Trace_Methods_Filter": "Trace method filter",
"Log_Trace_Methods_Filter_Description": "The text here will be evaluated as RegExp (`new RegExp('text')`). Keep it empty to show trace of every call.",
"Log_Trace_Methods": "Trace method calls",
"Log_Trace_Subscriptions_Filter": "Trace subscription filter",
"Log_Trace_Subscriptions_Filter_Description": "The text here will be evaluated as RegExp (`new RegExp('text')`). Keep it empty to show trace of every call.",
"Log_Trace_Subscriptions": "Trace subscription calls",
"Log_View_Limit": "Log View Limit",
"Logged_out_of_other_clients_successfully": "Logged out of other clients successfully",
"Login": "Login",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Package.onUse(function(api) {

api.addFiles('lib/core.js');

api.addFiles('lib/settings.js');

// DEBUGGER
api.addFiles('server/lib/debug.js', 'server');

Expand All @@ -54,7 +56,6 @@ Package.onUse(function(api) {

// COMMON LIB
api.addFiles('lib/getURL.js');
api.addFiles('lib/settings.js');
api.addFiles('lib/callbacks.js');
api.addFiles('lib/fileUploadRestrictions.js');
api.addFiles('lib/getAvatarColor.js');
Expand Down
33 changes: 33 additions & 0 deletions packages/rocketchat-lib/server/lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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});

Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,30 @@ RocketChat.settings.addGroup('Logs', function() {
type: 'int'
});

this.add('Log_Trace_Methods', false, {
type: 'boolean'
});

this.add('Log_Trace_Methods_Filter', '', {
type: 'string',
enableQuery: {
_id: 'Log_Trace_Methods',
value: true
}
});

this.add('Log_Trace_Subscriptions', false, {
type: 'boolean'
});

this.add('Log_Trace_Subscriptions_Filter', '', {
type: 'string',
enableQuery: {
_id: 'Log_Trace_Subscriptions',
value: true
}
});

this.section('Prometheus', function() {
this.add('Prometheus_Enabled', false, {
type: 'boolean',
Expand Down