-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.js
37 lines (33 loc) · 999 Bytes
/
logger.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
let DebugLogger = function(option) {
this.divname = option.divname || 'log_area';
}
DebugLogger.prototype.clear = function(arg1, arg2=''){
let debugbox = document.getElementById(that.divname);
if (debugbox) {
debugbox.innerHTML = '';
}
}
DebugLogger.prototype.log = function(arg1, arg2=''){
let that = this;
let header, text, out;
if (arg2 != undefined) {
header = arg1;
text = arg2;
}
let debugbox = document.getElementById(that.divname);
if (debugbox) {
if (arg1 == null) {
debugbox.innerHTML = '';
return;
}
if (typeof(text) == 'object') {
try {
out = JSON.stringify(text, undefined, 4);
}
catch(e) {alert(e)}
}
else out = text;
if (header) debugbox.innerHTML += `<br>${'-'.repeat(10)} ${header} ${'-'.repeat(87-header.length)}<br>` + out ;
else debugbox.innerHTML += `<br>${'-'.repeat(100)}<br>` + out;
}
}