UNPKG

1.02 kBJavaScriptView Raw
1/*
2
3 Lightweight logger, print everything that is send to error, warn
4 and messages to stdout (the terminal). If config.debug is set in config
5 also print out everything send to debug.
6
7*/
8
9var moment = require('moment');
10var fmt = require('util').format;
11var _ = require('underscore');
12var util = require('./util.js');
13var config = util.getConfig();
14
15var Log = function() {
16 this._debug = config.debug;
17 _.bindAll(this);
18};
19
20Log.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
46module.exports = new Log;
\No newline at end of file