1
// Copyright Joyent, Inc. and other Node contributors.
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22
var writeError = process.binding('stdio').writeError;
25
var formatRegExp = /%[sdj]/g;
27
var util = require('util');
29
if (typeof f !== 'string') {
31
for (var i = 0; i < arguments.length; i++) {
32
objects.push(util.inspect(arguments[i]));
34
return objects.join(' ');
40
var str = String(f).replace(formatRegExp, function(x) {
42
case '%s': return String(args[i++]);
43
case '%d': return Number(args[i++]);
44
case '%j': return JSON.stringify(args[i++]);
49
for (var len = args.length, x = args[i]; i < len; x = args[++i]) {
50
if (x === null || typeof x !== 'object') {
53
str += ' ' + util.inspect(x);
60
exports.log = function() {
61
process.stdout.write(format.apply(this, arguments) + '\n');
65
exports.info = exports.log;
68
exports.warn = function() {
69
writeError(format.apply(this, arguments) + '\n');
73
exports.error = exports.warn;
76
exports.dir = function(object) {
77
var util = require('util');
78
process.stdout.write(util.inspect(object) + '\n');
83
exports.time = function(label) {
84
times[label] = Date.now();
88
exports.timeEnd = function(label) {
89
var duration = Date.now() - times[label];
90
exports.log('%s: %dms', label, duration);
94
exports.trace = function(label) {
95
// TODO probably can to do this better with V8's debug object once that is
99
err.message = label || '';
100
Error.captureStackTrace(err, arguments.callee);
101
console.error(err.stack);
105
exports.assert = function(expression) {
107
var arr = Array.prototype.slice.call(arguments, 1);
108
require('assert').ok(false, format.apply(this, arr));