-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (40 loc) · 1.11 KB
/
app.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
'use strict';
const Homey = require('homey');
class MyApp extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
async onInit() {
this.log('MyApp has been initialized');
this.homey.settings.set('logger', JSON.stringify({ logs: [] }));
const saveLog = (type, message) => {
const s = this.homey.settings.get('logger');
const log = s ? JSON.parse(s) : {logs: []};
log.logs.push({time: new Date().toLocaleString(), message, type});
this.homey.settings.set('logger', JSON.stringify(log));
};
this.logger = {
debug: (message) => {
console.debug(message);
// saveLog('debug', message);
},
log: (message) => {
console.log(message);
// saveLog('log', message);
},
warn: (message) => {
console.warn(message);
// saveLog('warn', message);
},
info: (message) => {
console.info(message);
// saveLog('info', message);
},
error: (message) => {
console.error(message);
saveLog('error', message);
}
};
}
}
module.exports = MyApp;