jsonconsole.js
function write(src, lvl, obj) {

    var stack = null;
    var lvlInt = levels[lvl];
    var msg;

    if (   typeof process.env.LOG_LEVEL == "string" 
        && levels[process.env.LOG_LEVEL.toLowerCase()] > lvlInt) {
        return false;
    }

    if (process.env.JSONCONSOLE_DISABLE_JSON_OUTPUT) {
        return src.write(util.format(obj)+os.EOL);
    }

    if (lvlInt >= 40) {
        if (obj instanceof Error) {
            stack = obj.stack;
        } else {
            stack = new Error().stack.split("\n");
            stack.splice(1, 4); // obfuscate the trace inside the logger.
            stack = stack.join('\n');
        }
    }


    if (obj instanceof RawValue) {
        msg = util.inspect(obj.raw);
    } else if (typeof obj == "string") {
        msg = obj;
    } else {
        msg = util.inspect(obj);
    }

    var log = {
        name: options.name,
        hostname,
        pid: process.pid,
        level: lvlInt,
        msg: msg,
        time: options.localDate ? formatLocalDate() : new Date().toISOString(),
        src: getCaller3Info(),        
        levelName: levelNames[lvlInt],
    };

    if (obj instanceof RawValue) {
        log.raw = obj.raw;
    }

    stack = stack && options.root ? stack.replace(new RegExp(options.root, 'g'), '{root}') : stack;
    
    if (stack) {
        log.stack = stack;
    }

    log.v = options.v;
    log.src.r = options.root;

    return src.write(JSON.stringify(log) + os.EOL);
}
function write(src, lvl, obj) {

    var stack = null;
    var lvlInt = levels[lvl];
    var msg;

    if (   typeof process.env.LOG_LEVEL == "string" 
        && levels[process.env.LOG_LEVEL.toLowerCase()] > lvlInt) {
        return false;
    }

    if (process.env.JSONCONSOLE_DISABLE_JSON_OUTPUT) {
        return src.write(util.format(obj)+os.EOL);
    }

    if (lvlInt >= 40) {
        if (obj instanceof Error) {
            stack = obj.stack;
        } else {
            stack = new Error().stack.split("\n");
            stack.splice(1, 4); // obfuscate the trace inside the logger.
            stack = stack.join('\n');
        }
    }


    if (obj instanceof RawValue) {
        msg = util.inspect(obj.raw);
    } else if (typeof obj == "string") {
        msg = obj;
    } else {
        msg = util.inspect(obj);
    }

    var log = {
        name: options.name,
        hostname,
        pid: process.pid,
        level: lvlInt,
        msg: msg,
        time: options.localDate ? formatLocalDate() : new Date().toISOString(),
        src: getCaller3Info(),        
        levelName: levelNames[lvlInt],
    };

    if (obj instanceof RawValue) {
        log.raw = obj.raw;
    }

    stack = stack && options.root ? stack.replace(new RegExp(options.root, 'g'), '{root}') : stack;
    
    if (stack) {
        log.stack = stack;
    }

    log.v = options.v;
    log.src.r = options.root;

    return src.write(JSON.stringify(log) + os.EOL);
}
function write ( src , lvl , obj ) { var stack = null ; var lvlInt = levels [ lvl ] ; var msg ; if ( typeof process . env . LOG_LEVEL == "string" && levels [ process . env . LOG_LEVEL . toLowerCase ( ) ] > lvlInt ) { return false ; } if ( process . env . JSONCONSOLE_DISABLE_JSON_OUTPUT ) { return src . write ( util . format ( obj ) + os . EOL ) ; } if ( lvlInt >= 40 ) { if ( obj instanceof Error ) { stack = obj . stack ; } else { stack = new Error ( ) . stack . split ( "\n" ) ; stack . splice ( 1 , 4 ) ; // obfuscate the trace inside the logger. stack = stack . join ( '\n' ) ; } } if ( obj instanceof RawValue ) { msg = util . inspect ( obj . raw ) ; } else if ( typeof obj == "string" ) { msg = obj ; } else { msg = util . inspect ( obj ) ; } var log = { name : options . name , hostname , pid : process . pid , level : lvlInt , msg : msg , time : options . localDate ? formatLocalDate ( ) : new Date ( ) . toISOString ( ) , src : getCaller3Info ( ) , levelName : levelNames [ lvlInt ] , } ; if ( obj instanceof RawValue ) { log . raw = obj . raw ; } stack = stack && options . root ? stack . replace ( new RegExp ( options . root , 'g' ) , '{root}' ) : stack ; if ( stack ) { log . stack = stack ; } log . v = options . v ; log . src . r = options . root ; return src . write ( JSON . stringify ( log ) + os . EOL ) ; }
Write JSON log line to stderr & stdout

@param  {Stream} src stderr or stdout
@param  {String} lvl a given string level by calling console.{level}()
@param  {Object} obj Any object that will be filtered
@return {Boolean} false if logging has aborted
Write JSON log line to stderr & stdout