cocalc/src / smc-project / node_modules / cliff / node_modules / winston / lib / winston / transports / console.js
50675 views/*1* console.js: Transport for outputting to the console2*3* (C) 2010 Charlie Robbins4* MIT LICENCE5*6*/78var events = require('events'),9util = require('util'),10colors = require('colors'),11common = require('../common'),12Transport = require('./transport').Transport;1314//15// ### function Console (options)16// #### @options {Object} Options for this instance.17// Constructor function for the Console transport object responsible18// for persisting log messages and metadata to a terminal or TTY.19//20var Console = exports.Console = function (options) {21Transport.call(this, options);22options = options || {};2324this.name = 'console';25this.json = options.json || false;26this.colorize = options.colorize || false;27this.prettyPrint = options.prettyPrint || false;28this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;2930if (this.json) {31this.stringify = options.stringify || function (obj) {32return JSON.stringify(obj, null, 2);33};34}35};3637//38// Inherit from `winston.Transport`.39//40util.inherits(Console, Transport);4142//43// Expose the name of this Transport on the prototype44//45Console.prototype.name = 'console';4647//48// ### function log (level, msg, [meta], callback)49// #### @level {string} Level at which to log the message.50// #### @msg {string} Message to log51// #### @meta {Object} **Optional** Additional metadata to attach52// #### @callback {function} Continuation to respond to when complete.53// Core logging method exposed to Winston. Metadata is optional.54//55Console.prototype.log = function (level, msg, meta, callback) {56if (this.silent) {57return callback(null, true);58}5960var self = this,61output;6263output = common.log({64colorize: this.colorize,65json: this.json,66level: level,67message: msg,68meta: meta,69stringify: this.stringify,70timestamp: this.timestamp,71prettyPrint: this.prettyPrint,72raw: this.raw73});7475if (level === 'error' || level === 'debug') {76console.error(output);77} else {78console.log(output);79}8081//82// Emit the `logged` event immediately because the event loop83// will not exit until `process.stdout` has drained anyway.84//85self.emit('logged');86callback(null, true);87};888990