Mercurial > hg > nodescore
comparison node_modules/socket.io/lib/logger.js @ 69:333afcfd3f3a
added node_modules to project and fixed path to chronometer
also added deps to installer script
author | tzara <rc-web@kiben.net> |
---|---|
date | Sat, 26 Oct 2013 14:12:50 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68:b076cd17638c | 69:333afcfd3f3a |
---|---|
1 | |
2 /*! | |
3 * socket.io-node | |
4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com> | |
5 * MIT Licensed | |
6 */ | |
7 | |
8 /** | |
9 * Module dependencies. | |
10 */ | |
11 | |
12 var util = require('./util') | |
13 , toArray = util.toArray; | |
14 | |
15 /** | |
16 * Log levels. | |
17 */ | |
18 | |
19 var levels = [ | |
20 'error' | |
21 , 'warn' | |
22 , 'info' | |
23 , 'debug' | |
24 ]; | |
25 | |
26 /** | |
27 * Colors for log levels. | |
28 */ | |
29 | |
30 var colors = [ | |
31 31 | |
32 , 33 | |
33 , 36 | |
34 , 90 | |
35 ]; | |
36 | |
37 /** | |
38 * Pads the nice output to the longest log level. | |
39 */ | |
40 | |
41 function pad (str) { | |
42 var max = 0; | |
43 | |
44 for (var i = 0, l = levels.length; i < l; i++) | |
45 max = Math.max(max, levels[i].length); | |
46 | |
47 if (str.length < max) | |
48 return str + new Array(max - str.length + 1).join(' '); | |
49 | |
50 return str; | |
51 }; | |
52 | |
53 /** | |
54 * Logger (console). | |
55 * | |
56 * @api public | |
57 */ | |
58 | |
59 var Logger = module.exports = function (opts) { | |
60 opts = opts || {} | |
61 this.colors = false !== opts.colors; | |
62 this.level = 3; | |
63 this.enabled = true; | |
64 }; | |
65 | |
66 /** | |
67 * Log method. | |
68 * | |
69 * @api public | |
70 */ | |
71 | |
72 Logger.prototype.log = function (type) { | |
73 var index = levels.indexOf(type); | |
74 | |
75 if (index > this.level || !this.enabled) | |
76 return this; | |
77 | |
78 console.log.apply( | |
79 console | |
80 , [this.colors | |
81 ? ' \033[' + colors[index] + 'm' + pad(type) + ' -\033[39m' | |
82 : type + ':' | |
83 ].concat(toArray(arguments).slice(1)) | |
84 ); | |
85 | |
86 return this; | |
87 }; | |
88 | |
89 /** | |
90 * Generate methods. | |
91 */ | |
92 | |
93 levels.forEach(function (name) { | |
94 Logger.prototype[name] = function () { | |
95 this.log.apply(this, [name].concat(toArray(arguments))); | |
96 }; | |
97 }); |