Browse Source

Add sys.log()

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
9be3df0828
  1. 2
      doc/api.txt
  2. 19
      lib/sys.js

2
doc/api.txt

@ -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

@ -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 = "";

Loading…
Cancel
Save