forked from winstonjs/winston
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winston.js
97 lines (83 loc) · 2.71 KB
/
winston.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
87
88
89
90
91
92
93
94
95
96
97
/*
* winston.js: Top-level include defining Winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
var winston = exports;
//
// Expose version using `pkginfo`
//
require('pkginfo')(module, 'version');
//
// Include transports defined by default by winston
//
winston.transports = require('./winston/transports');
//
// function findTransport (transport)
// Helper method to find existing transport
//
winston.findTransport = function (transport) {
var name, existing = Object.keys(winston.transports).filter(function (k) {
return winston.transports[k] === transport;
});
return existing.length > 0 ? existing[0].toLowerCase() : null;
};
var internal = require('./winston/internal');
winston.hash = internal.hash;
winston.clone = internal.clone;
winston.longestElement = internal.longestElement;
winston.config = require('./winston/config');
winston.addColors = winston.config.addColors;
winston.Logger = require('winston/logger').Logger;
//
// We create and expose a 'defaultLogger' so that the programmer may do the
// following without the need to create an instance of winston.Logger directly:
// var winston = require('winston');
// winston.log('info', 'some message');
// winston.error('some error');
//
var defaultLogger = new (winston.Logger)({ transports: [new (winston.transports.Console)()] });
internal.setLevels(winston, null, defaultLogger.levels);
['log', 'add', 'remove', 'profile', 'extend', 'cli'].forEach(function (method) {
winston[method] = function () {
return defaultLogger[method].apply(defaultLogger, arguments);
};
});
winston.cli = function (foo, bar) {
winston.padLevels = true;
internal.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
defaultLogger.setLevels(winston.config.cli.levels);
winston.config.addColors(winston.config.cli.colors);
if (defaultLogger.transports.console) {
defaultLogger.transports.console.colorize = true;
defaultLogger.transports.console.timestamp = false;
}
return winston;
};
winston.setLevels = function (levels) {
internal.setLevels(winston, defaultLogger.levels, levels);
defaultLogger.setLevels(levels);
};
//
// Define getters / setters for appropriate properties of the
// default logger which need to be exposed by winston.
//
['emitErrs', 'padLevels', 'levelLength'].forEach(function (prop) {
Object.defineProperty(winston, prop, {
get: function () {
return defaultLogger[prop];
},
set: function (val) {
defaultLogger[prop] = val;
}
});
});
//
// function defaultTransports ()
// returns the transports set on the default winston logger
//
winston.defaultTransports = function () {
return defaultLogger.transports;
};