forked from delian/node-rtmpapi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.js
More file actions
78 lines (70 loc) · 1.62 KB
/
Copy pathlog.js
File metadata and controls
78 lines (70 loc) · 1.62 KB
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
/**
* Created by delian on 3/11/14.
* Easy implementation of Logging. Always print Data and some prefix in front of it
*/
var encodeLookup = '0123456789abcdef'.split('');
var decodeLookup = [];
var i = 0;
while (i < 10) decodeLookup[0x30 + i] = i++;
while (i < 16) decodeLookup[0x61 - 10 + i] = i++;
function dumpArray(array, type, headLen, lineLen)
{
var length = array.length;
var string = '';
var c, i = 0;
if (type == 'char')
{
while (i < length)
{
c = array[i++];
if (c > 32 && c <= 126)
string += String.fromCharCode(c);
else
string += '.';
if (i >= headLen && (i - headLen) % (2 * lineLen) == 0)
string += '\n';
else if (i == headLen || (i > headLen && (i - headLen) % lineLen == 0))
string += ' ';
}
} else
{
while (i < length)
{
c = array[i++];
string += encodeLookup[(c & 0xF0) >> 4] + encodeLookup[c & 0xF];
string += ' ';
if (i >= headLen && (i - headLen) % (2 * lineLen) == 0)
string += '\n';
else if (i == headLen || (i > headLen && (i - headLen) % lineLen == 0))
string += ' ';
}
}
return string
}
module.exports = function (sDebug, sRaddr)
{
var debug = sDebug;
var raddr = sRaddr || 'none';
return {
log: function ()
{
if (debug)
{
for (var z = [], k = arguments.length - 1; k >= 0; k--) z[k] = arguments[k];
//console.log.apply(this, z);//[/*new Date,raddr,*/'>'].concat(z));
}
},
debug: function (sDebug)
{
debug = sDebug;
},
raddr: function (sRaddr)
{
raddr = sRaddr;
},
dumpArray: function (array, type, headLen, lineLen)
{
console.log(dumpArray(array, type, headLen, lineLen));
}
};
};