d6ad5f955dd741422100249deca7f9bc33722585.svn-base
2.16 KB
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
87
/*
* console.js: Transport for outputting to the console
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
var events = require('events'),
util = require('util'),
colors = require('colors'),
common = require('../common'),
Transport = require('./transport').Transport;
//
// ### function Console (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Console transport object responsible
// for persisting log messages and metadata to a terminal or TTY.
//
var Console = exports.Console = function (options) {
Transport.call(this, options);
options = options || {};
this.name = 'console';
this.json = options.json || false;
this.colorize = options.colorize || false;
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
if (this.json) {
this.stringify = options.stringify || function (obj) {
return JSON.stringify(obj, null, 2);
};
}
};
//
// Inherit from `winston.Transport`.
//
util.inherits(Console, Transport);
//
// Expose the name of this Transport on the prototype
//
Console.prototype.name = 'console';
//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
Console.prototype.log = function (level, msg, meta, callback) {
if (this.silent) {
return callback(null, true);
}
var self = this,
output;
output = common.log({
colorize: this.colorize,
json: this.json,
level: level,
message: msg,
meta: meta,
stringify: this.stringify,
timestamp: this.timestamp,
raw: this.raw
});
if (level === 'error' || level === 'debug') {
util.error(output);
}
else {
util.puts(output);
}
//
// Emit the `logged` event immediately because the event loop
// will not exit until `process.stdout` has drained anyway.
//
self.emit('logged');
callback(null, true);
};