2 * winston.js: Top-level include defining Winston.
4 * (C) 2010 Charlie Robbins
12 // Expose version using `pkginfo`
14 require('pkginfo')(module, 'version');
17 // Include transports defined by default by winston
19 winston.transports = require('./winston/transports');
22 // Expose utility methods
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;
33 // Expose core Logging-related prototypes.
35 winston.Container = require('./winston/container').Container;
36 winston.Logger = require('./winston/logger').Logger;
37 winston.Transport = require('./winston/transports/transport').Transport;
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.
45 // var logger = require('winston').loggers.get('something');
49 // var logger = require('winston').loggers.get('something');
51 winston.loggers = new winston.Container();
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:
57 // var winston = require('winston');
58 // winston.log('info', 'some message');
59 // winston.error('some error');
61 var defaultLogger = new winston.Logger({
62 transports: [new winston.transports.Console()]
66 // Pass through the target methods onto `winston.
79 common.setLevels(winston, null, defaultLogger.levels);
80 methods.forEach(function (method) {
81 winston[method] = function () {
82 return defaultLogger[method].apply(defaultLogger, arguments);
87 // ### function cli ()
88 // Configures the default winston logger to have the
89 // settings for command-line interfaces: no timestamp,
90 // colors enabled, padded output, and additional levels.
92 winston.cli = function () {
93 winston.padLevels = true;
94 common.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
95 defaultLogger.setLevels(winston.config.cli.levels);
96 winston.config.addColors(winston.config.cli.colors);
98 if (defaultLogger.transports.console) {
99 defaultLogger.transports.console.colorize = true;
100 defaultLogger.transports.console.timestamp = false;
107 // ### function setLevels (target)
108 // #### @target {Object} Target levels to use
109 // Sets the `target` levels specified on the default winston logger.
111 winston.setLevels = function (target) {
112 common.setLevels(winston, defaultLogger.levels, target);
113 defaultLogger.setLevels(target);
117 // Define getters / setters for appropriate properties of the
118 // default logger which need to be exposed by winston.
120 ['emitErrs', 'exitOnError', 'padLevels', 'level', 'levelLength', 'stripColors'].forEach(function (prop) {
121 Object.defineProperty(winston, prop, {
123 return defaultLogger[prop];
125 set: function (val) {
126 defaultLogger[prop] = val;
133 // The default transports and exceptionHandlers for
134 // the default winston logger.
136 Object.defineProperty(winston, 'default', {
139 transports: defaultLogger.transports,
140 exceptionHandlers: defaultLogger.exceptionHandlers