Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* winston.js: Top-level include defining Winston.
3
*
4
* (C) 2010 Charlie Robbins
5
* MIT LICENCE
6
*
7
*/
8
9
var winston = exports;
10
11
//
12
// Expose version using `pkginfo`
13
//
14
require('pkginfo')(module, 'version');
15
16
//
17
// Include transports defined by default by winston
18
//
19
winston.transports = require('./winston/transports');
20
21
//
22
// Expose utility methods
23
//
24
var common = require('./winston/common');
25
winston.hash = common.hash;
26
winston.clone = common.clone;
27
winston.longestElement = common.longestElement;
28
winston.exception = require('./winston/exception');
29
winston.config = require('./winston/config');
30
winston.addColors = winston.config.addColors;
31
32
//
33
// Expose core Logging-related prototypes.
34
//
35
winston.Container = require('./winston/container').Container;
36
winston.Logger = require('./winston/logger').Logger;
37
winston.Transport = require('./winston/transports/transport').Transport;
38
39
//
40
// We create and expose a default `Container` to `winston.loggers` so that the
41
// programmer may manage multiple `winston.Logger` instances without any additional overhead.
42
//
43
// ### some-file1.js
44
//
45
// var logger = require('winston').loggers.get('something');
46
//
47
// ### some-file2.js
48
//
49
// var logger = require('winston').loggers.get('something');
50
//
51
winston.loggers = new winston.Container();
52
53
//
54
// We create and expose a 'defaultLogger' so that the programmer may do the
55
// following without the need to create an instance of winston.Logger directly:
56
//
57
// var winston = require('winston');
58
// winston.log('info', 'some message');
59
// winston.error('some error');
60
//
61
var defaultLogger = new winston.Logger({
62
transports: [new winston.transports.Console()]
63
});
64
65
//
66
// Pass through the target methods onto `winston.
67
//
68
var methods = [
69
'log',
70
'query',
71
'stream',
72
'add',
73
'remove',
74
'profile',
75
'startTimer',
76
'extend',
77
'cli',
78
'handleExceptions',
79
'unhandleExceptions'
80
];
81
common.setLevels(winston, null, defaultLogger.levels);
82
methods.forEach(function (method) {
83
winston[method] = function () {
84
return defaultLogger[method].apply(defaultLogger, arguments);
85
};
86
});
87
88
//
89
// ### function cli ()
90
// Configures the default winston logger to have the
91
// settings for command-line interfaces: no timestamp,
92
// colors enabled, padded output, and additional levels.
93
//
94
winston.cli = function () {
95
winston.padLevels = true;
96
common.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
97
defaultLogger.setLevels(winston.config.cli.levels);
98
winston.config.addColors(winston.config.cli.colors);
99
100
if (defaultLogger.transports.console) {
101
defaultLogger.transports.console.colorize = true;
102
defaultLogger.transports.console.timestamp = false;
103
}
104
105
return winston;
106
};
107
108
//
109
// ### function setLevels (target)
110
// #### @target {Object} Target levels to use
111
// Sets the `target` levels specified on the default winston logger.
112
//
113
winston.setLevels = function (target) {
114
common.setLevels(winston, defaultLogger.levels, target);
115
defaultLogger.setLevels(target);
116
};
117
118
//
119
// Define getters / setters for appropriate properties of the
120
// default logger which need to be exposed by winston.
121
//
122
['emitErrs', 'exitOnError', 'padLevels', 'level', 'levelLength', 'stripColors'].forEach(function (prop) {
123
Object.defineProperty(winston, prop, {
124
get: function () {
125
return defaultLogger[prop];
126
},
127
set: function (val) {
128
defaultLogger[prop] = val;
129
}
130
});
131
});
132
133
//
134
// @default {Object}
135
// The default transports and exceptionHandlers for
136
// the default winston logger.
137
//
138
Object.defineProperty(winston, 'default', {
139
get: function () {
140
return {
141
transports: defaultLogger.transports,
142
exceptionHandlers: defaultLogger.exceptionHandlers
143
};
144
}
145
});
146
147