Skip to content

Commit 0365730

Browse files
committed
Initial commit
0 parents  commit 0365730

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed

History.md

Whitespace-only changes.

Makefile

Whitespace-only changes.

Readme.md

Whitespace-only changes.

example.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var Log = require('./lib/log');
7+
8+
var log = new Log(Log.INFO);
9+
10+
log.debug('preparing email');
11+
log.info('sending email');
12+
log.error('failed to send email');

lib/log.js

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
2+
/*!
3+
* Log.js
4+
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
5+
* MIT Licensed
6+
*/
7+
8+
/**
9+
* Initialize a `Loggeer` with the given log `level` defaulting
10+
* to __DEBUG__ and `stream` defaulting to _stdout_.
11+
*
12+
* @param {Number} level
13+
* @param {Object} stream
14+
* @api public
15+
*/
16+
17+
var Log = exports = module.exports = function Log(level, stream){
18+
this.level = level || exports.DEBUG;
19+
this.stream = stream || process.stdout;
20+
};
21+
22+
/**
23+
* System is unusable.
24+
*
25+
* @type Number
26+
*/
27+
28+
exports.EMERGENCY = 0;
29+
30+
/**
31+
* Action must be taken immediately.
32+
*
33+
* @type Number
34+
*/
35+
36+
exports.ALERT = 1;
37+
38+
/**
39+
* Critical condition.
40+
*
41+
* @type Number
42+
*/
43+
44+
exports.CRITICAL = 2;
45+
46+
/**
47+
* Error condition.
48+
*
49+
* @type Number
50+
*/
51+
52+
exports.ERROR = 3;
53+
54+
/**
55+
* Warning condition.
56+
*
57+
* @type Number
58+
*/
59+
60+
exports.WARNING = 4;
61+
62+
/**
63+
* Normal but significant condition.
64+
*
65+
* @type Number
66+
*/
67+
68+
exports.NOTICE = 5;
69+
70+
/**
71+
* Purely informational message.
72+
*
73+
* @type Number
74+
*/
75+
76+
exports.INFO = 6;
77+
78+
/**
79+
* Application debug messages.
80+
*
81+
* @type Number
82+
*/
83+
84+
exports.DEBUG = 7;
85+
86+
/**
87+
* prototype.
88+
*/
89+
90+
Log.prototype = {
91+
92+
/**
93+
* Log output message.
94+
*
95+
* @param {String} levelStr
96+
* @param {String} msg
97+
* @api private
98+
*/
99+
100+
log: function(levelStr, msg) {
101+
if (exports[levelStr] <= this.level) {
102+
this.stream.write([
103+
'[' + (new Date).toUTCString() + ']'
104+
, '-'
105+
, levelStr
106+
, '-'
107+
, msg
108+
].join(' ' ) + '\n');
109+
}
110+
},
111+
112+
/**
113+
* Log emergency `msg`.
114+
*
115+
* @param {String} msg
116+
* @api public
117+
*/
118+
119+
emergency: function(msg){
120+
this.log('EMERGENCY', msg);
121+
},
122+
123+
/**
124+
* Log alert `msg`.
125+
*
126+
* @param {String} msg
127+
* @api public
128+
*/
129+
130+
alert: function(msg){
131+
this.log('ALERT', msg);
132+
},
133+
134+
/**
135+
* Log critical `msg`.
136+
*
137+
* @param {String} msg
138+
* @api public
139+
*/
140+
141+
critical: function(msg){
142+
this.log('CRITICAL', msg);
143+
},
144+
145+
/**
146+
* Log error `msg`.
147+
*
148+
* @param {String} msg
149+
* @api public
150+
*/
151+
152+
error: function(msg){
153+
this.log('ERROR', msg);
154+
},
155+
156+
/**
157+
* Log warning `msg`.
158+
*
159+
* @param {String} msg
160+
* @api public
161+
*/
162+
163+
warning: function(msg){
164+
this.log('WARNING', msg);
165+
},
166+
167+
/**
168+
* Log notice `msg`.
169+
*
170+
* @param {String} msg
171+
* @api public
172+
*/
173+
174+
notice: function(msg){
175+
this.log('NOTICE', msg);
176+
},
177+
178+
/**
179+
* Log info `msg`.
180+
*
181+
* @param {String} msg
182+
* @api public
183+
*/
184+
185+
info: function(msg){
186+
this.log('INFO', msg);
187+
},
188+
189+
/**
190+
* Log debug `msg`.
191+
*
192+
* @param {String} msg
193+
* @api public
194+
*/
195+
196+
debug: function(msg){
197+
this.log('DEBUG', msg);
198+
}
199+
};

0 commit comments

Comments
 (0)