Code coverage report for lib/log.js

Statements: 95.24% (40 / 42)      Branches: 90% (18 / 20)      Functions: 100% (11 / 11)      Lines: 95.24% (40 / 42)     

All files » lib/ » log.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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86          1 1   1 1   1   1   1 2     1 8 8     1 15 15 15     15     1 1691     1691       1 274 92       1 122 24       1 17 13       1 9 1   9     1 21 8         1   520 3       1023 4        
/*
Copyright (c) 2012, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://yuilibrary.com/license/
*/
var color = require('ansi-color').set;
var hasColor = process.stdin.isTTY;
 
var quiet;
var silent;
 
var prefix;
 
exports.isTTY = hasColor;
 
exports.quiet = function () {
    quiet = true;
};
 
exports.silent = function () {
    silent = true;
    quiet = true;
};
 
exports.reset = function(options) {
    silent = false;
    quiet = false;
    Iif (options && options.color === false) {
        hasColor = false;
    }
    prefix = exports.color('shifter', 'magenta');
};
 
exports.color = function (str, code) {
    Iif (!hasColor) {
        return str;
    }
    return color(str, code);
};
 
 
exports.info = function (str) {
    if (!quiet) {
        console.log(prefix, exports.color('[info]', 'white'), str);
    }
};
 
exports.log = function (str) {
    if (!quiet) {
        console.log(prefix, exports.color('[queu]', 'cyan'), str);
    }
};
 
exports.warn = function (str) {
    if (!silent) {
        console.log(prefix, exports.color('[warn]', 'yellow'), str);
    }
};
 
exports.error = function (str) {
    if (!silent) {
        console.error(prefix, exports.color('[error]', 'red'), str);
    }
    process.exit(1);
};
 
exports.err = function (str) {
    if (!silent) {
        console.error(prefix, exports.color('[err]', 'red'), str);
    }
};
 
 
exports.console = {
    log: function() {
        if (!quiet) {
            console.log.apply(this, arguments);
        }
    },
    error: function() {
        if (!silent) {
            console.error.apply(this, arguments);
        }
    }
};