diff --git a/doc/api.txt b/doc/api.txt index 73f4f54c2e..9466fc6e45 100644 --- a/doc/api.txt +++ b/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)+ :: diff --git a/lib/sys.js b/lib/sys.js index 5ad68e4926..a828e5cef5 100644 --- a/lib/sys.js +++ b/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 = "";