Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / node_modules / prompt / node_modules / winston / lib / winston.js
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   'add', 
71   'remove', 
72   'profile', 
73   'startTimer',
74   'extend', 
75   'cli', 
76   'handleExceptions', 
77   'unhandleExceptions'
78 ];
79 common.setLevels(winston, null, defaultLogger.levels);
80 methods.forEach(function (method) {
81   winston[method] = function () {
82     return defaultLogger[method].apply(defaultLogger, arguments);
83   };
84 });
85
86 //
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.
91 //
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);
97   
98   if (defaultLogger.transports.console) {
99     defaultLogger.transports.console.colorize = true;
100     defaultLogger.transports.console.timestamp = false;
101   }
102   
103   return winston;
104 };
105
106 //
107 // ### function setLevels (target)
108 // #### @target {Object} Target levels to use
109 // Sets the `target` levels specified on the default winston logger.
110 //
111 winston.setLevels = function (target) {
112   common.setLevels(winston, defaultLogger.levels, target);
113   defaultLogger.setLevels(target);
114 };
115
116 //
117 // Define getters / setters for appropriate properties of the 
118 // default logger which need to be exposed by winston.
119 //
120 ['emitErrs', 'exitOnError', 'padLevels', 'level', 'levelLength', 'stripColors'].forEach(function (prop) {
121   Object.defineProperty(winston, prop, {
122     get: function () {
123       return defaultLogger[prop];
124     },
125     set: function (val) {
126       defaultLogger[prop] = val;
127     }
128   });
129 });
130
131 //
132 // @default {Object} 
133 // The default transports and exceptionHandlers for 
134 // the default winston logger.
135 //
136 Object.defineProperty(winston, 'default', {
137   get: function () {
138     return {
139       transports: defaultLogger.transports,
140       exceptionHandlers: defaultLogger.exceptionHandlers
141     };
142   }
143 });