-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrail_monitor.js
72 lines (59 loc) · 2.82 KB
/
trail_monitor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Setting keys:
var KEYS = {
MONITOR: {
MONITOR: 'monitor',
MONITORS: 'monitors',
MONITOR_PUBLISH_NAME: 'monitor_name',
MONITOR_DEFAULT_LIMIT: 'monitor_default_limit',
MONITOR_CONSOLE: 'monitor_console',
MONITOR_CONSOLE_SHOW: 'show',
MONITOR_CONSOLE_THEME: 'theme',
MONITOR_CONSOLE_LARGE: 'large',
MONITOR_CONSOLE_WRAP: 'wrap'
}
};
Trail.Settings.KEYS.MONITOR = KEYS.MONITOR;
// Handle monitoring settings:
var clientSettings = Trail.Settings.clientSettings;
if (clientSettings[KEYS.MONITOR.MONITOR]) {
Trail.Settings.Config.monitor = true;
Trail.Settings.Config.monitorPublishName = clientSettings[KEYS.MONITOR.MONITOR_PUBLISH_NAME] || 'trail/latestmessages';
Trail.Settings.Config.monitorDefaultLimit = typeof clientSettings[KEYS.MONITOR.MONITOR_DEFAULT_LIMIT] === 'number' ? clientSettings[KEYS.MONITOR.MONITOR_DEFAULT_LIMIT] : 200;
var monitorConsole = clientSettings[KEYS.MONITOR.MONITOR_CONSOLE];
Trail.Settings.Config.monitorConsole = !!monitorConsole;
Trail.Settings.Config.monitorConsoleShow = typeof monitorConsole === 'object' && !!monitorConsole[KEYS.MONITOR.MONITOR_CONSOLE_SHOW];
Trail.Settings.Config.monitorConsoleTheme = typeof monitorConsole === 'object' && typeof monitorConsole[KEYS.MONITOR.MONITOR_CONSOLE_THEME] === 'string' ? monitorConsole[KEYS.MONITOR.MONITOR_CONSOLE_THEME] : null;
Trail.Settings.Config.monitorConsoleLarge = typeof monitorConsole === 'object' && !!monitorConsole[KEYS.MONITOR.MONITOR_CONSOLE_LARGE];
Trail.Settings.Config.monitorConsoleWrap = typeof monitorConsole === 'object' && !!monitorConsole[KEYS.MONITOR.MONITOR_CONSOLE_WRAP];
if (clientSettings[KEYS.MONITOR.MONITORS] instanceof Array) {
Trail.Settings.Config.monitors = clientSettings[KEYS.MONITOR.MONITORS];
}
else {
Trail.Settings.Config.monitors = [{name: 'Server + Client'}];
}
}
if (Trail.Settings.Config.monitor) {
Trail.Util.constructSelectorFromFilter = function(filter, origin_id) {
var selector = {};
filter = typeof filter === 'object' ? filter : {};
if (typeof filter.level === 'string') {
var filterLevelValue = Trail.LOG_LEVELS[filter.level];
if (typeof filterLevelValue === 'number') {
selector.levelValue = {$lte: filterLevelValue};
}
}
if (filter.server && !filter.client) {
selector['meta._origin'] = 'server';
}
else if (filter.client && !filter.server) {
selector['meta._origin'] = 'client';
}
if (!filter.other_clients) {
selector['$or'] = [{'meta._origin_id': origin_id}, {'meta._origin': {$ne: 'client'}}];
}
if (filter.tag) {
selector['meta.tag'] = filter.tag;
}
return selector;
};
}