-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-Logging.js
executable file
·77 lines (66 loc) · 2.43 KB
/
MMM-Logging.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
72
73
74
75
76
77
/* global Module */
/* MagicMirror²
* Module: MMM-Logging
*
* By shbatm
* MIT Licensed.
*/
/* jshint esversion: 6 */
Module.register("MMM-Logging", {
defaults: {
useColor: true,
format: "{{timestamp}} <{{title}}> {{message}} ({{folder}}/{{file}}:{{line}} {{method}})",
overwriteConsoleMethods: true,
overwriteBrowserMethods: false,
echoModuleNotifications: 'notification',
echoErrors: true,
dateformat: "yyyy-mm-dd'T'HH:MM:ss",
ignoreModules: [ 'calendar', 'newsfeed', 'clock' ]
},
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function() {
this.sendSocketNotification("INITIALIZE_LOGGING", this.config);
if (this.config.overwriteBrowserMethods) {
this.config.overwriteConsoleMethods = true;
// Overwrite the Main Console
this.console = Tracer.console(this.config);
// Overwrite MagicMirror's Log functions.
Log.log = console.log;
Log.info = console.info;
Log.warn = console.warn;
Log.error = console.error;
Log.debug = (console.debug || console.log);
}
console.info("MMM-Logging updated window.console.");
if (this.config.echoErrors) {
console.error = (text) => {
this.sendSocketNotification("BROWSER_ERROR", text);
this.console.error(text);
};
window.addEventListener('error', (event) => {
this.sendSocketNotification("BROWSER_ERROR", event);
});
}
this.initialized = true;
},
getScripts: function() {
return ['tracer-bundle.js'];
},
getStyles: function() {
return [];
},
// socketNotificationReceived from helper
socketNotificationReceived: function(notification, payload) {
// Do nothing.
},
notificationReceived: function(notification, payload, sender) {
if (this.config.echoModuleNotifications) {
if (sender && this.config.ignoreModules && this.config.ignoreModules.indexOf(sender.name) !== -1) { return; }
this.sendSocketNotification("NOTIFICATION_TO_CONSOLE", {
notification: notification,
payload: (payload && this.config.echoModuleNotifications === "payload") ? payload : undefined,
sender: (sender) ? sender.name : undefined
});
}
},
});