-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.js
51 lines (43 loc) · 995 Bytes
/
Console.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
"use strict";
function trace ( msg=null )
{
msg = msg || "";
let s = new Error().stack ;
if ( s.startsWith("trace@file") ) { // Firefox
var line = s.split('\n')[1];
let fields = line.split('@')
var fun = fields[0];
}
else if ( s.startsWith("Error") ) { // Chrome
var line = s.split('\n')[2];
var fun = line.split(' ')[5] ;
}
else {
var fun = s ;
}
console.log(fun+": "+msg);
}
// Replace log and clear functions.
//
console.redirect = function ( v )
{
if ( v ) {
console.org_log = console.log ;
console.log = function ( s ) {
v.textContent += s+"\n" ;
v.scrollTop = v.scrollHeight ;
};
console.org_clear = console.clear ;
console.clear = function ( ) {
v.textContent="";
};
}
else {
if ( console.org_log )
console.log = console.org_log ;
console.org_log = undefined ;
if ( console.org_clear )
console.clear = console.org_clear ;
console.org_clear = undefined ;
}
};