-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions.js
52 lines (47 loc) · 1.21 KB
/
functions.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
var params = require('./params');
// Datumsberechnungen
var getToday =
{
myHumanReadable: function()
{
var day = new Date();
return pad((+day.getDate()),2) + '.' + pad((+day.getMonth() + 1),2) + '.' + day.getFullYear() + ' ' + pad((+day.getHours()),2) + ':' + pad((+day.getMinutes()),2) + ':' + pad((+day.getSeconds()),2) + ' ';
},
day: function()
{
var trenn = '-';
var day = new Date();
return day.getFullYear() + trenn + pad((+day.getMonth() + 1),2) + trenn + pad((+day.getDate()),2);
},
};
exports.mylog = function(msg,level)
{
if (typeof(level) === 'undefined') level = 0;
if (level <= params.debug)
{
console.log(getToday.myHumanReadable() + msg);
}
}
exports.myerr = function(socket, tag, data, err)
{
if (params.debug > 0) {
console.log(getToday.myHumanReadable() + ' ' + err + ' occured at ' + tag + ' (maybe the next log entry shows the corrupted data)');
console.log(data);
}
var errdata = {
tag: tag,
errmsg: err,
data: data
};
socket.emit('requestError', errdata);
}
function pad(number, length)
{
var str = '' + number;
while (str.length < length)
{
str = '0' + str;
}
return str;
}
exports.getToday = getToday;