1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var moment = require('moment');
|
10 | var fmt = require('util').format;
|
11 | var _ = require('underscore');
|
12 | var util = require('./util.js');
|
13 | var config = util.getConfig();
|
14 |
|
15 | var Log = function() {
|
16 | this._debug = config.debug;
|
17 | _.bindAll(this);
|
18 | };
|
19 |
|
20 | Log.prototype = {
|
21 | _write: function(method, args, name) {
|
22 | if(!name)
|
23 | name = method.toUpperCase();
|
24 |
|
25 | var message = moment().format('YYYY-MM-DD HH:mm:ss');
|
26 | message += ' (' + name + '):\t';
|
27 | message += fmt.apply(null, args);
|
28 |
|
29 | console[method](message);
|
30 | },
|
31 | error: function() {
|
32 | this._write('error', arguments);
|
33 | },
|
34 | warn: function() {
|
35 | this._write('warn', arguments);
|
36 | },
|
37 | info: function() {
|
38 | this._write('info', arguments);
|
39 | },
|
40 | debug: function() {
|
41 | if(this._debug)
|
42 | this._write('info', arguments, 'DEBUG');
|
43 | }
|
44 | }
|
45 |
|
46 | module.exports = new Log; |
\ | No newline at end of file |