Add sys.log()
This commit is contained in:
Родитель
6670154819
Коммит
9be3df0828
|
@ -187,6 +187,8 @@ Like +puts()+ but without the trailing new-line.
|
|||
A synchronous output function. Will block the process and
|
||||
output +string+ immediately to +stdout+.
|
||||
|
||||
+log(string)+::
|
||||
Output with timestamp.
|
||||
|
||||
|
||||
+inspect(object, showHidden, depth)+ ::
|
||||
|
|
19
lib/sys.js
19
lib/sys.js
|
@ -188,6 +188,25 @@ exports.p = function () {
|
|||
}
|
||||
};
|
||||
|
||||
function pad (n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
// 26 Feb 16:19:34
|
||||
function timestamp () {
|
||||
var d = new Date();
|
||||
return [ d.getDate()
|
||||
, months[d.getMonth()]
|
||||
, [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':')
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
exports.log = function (msg) {
|
||||
exports.puts(timestamp() + ' - ' + msg.toString());
|
||||
}
|
||||
|
||||
exports.exec = function (command, callback) {
|
||||
var child = process.createChildProcess("/bin/sh", ["-c", command]);
|
||||
var stdout = "";
|
||||
|
|
Загрузка…
Ссылка в новой задаче