-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
stream.js
63 lines (53 loc) · 1.04 KB
/
stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var _ = require('lodash');
/**
* Logger stream.
*
* This is an abstract class. Every logger stream should inherit this class and implement `_write` method. For example:
*
* ``` js
* var CustomStream = function(logger, options){
* Stream.apply(this, arguments);
* };
*
* CustomStream.prototype.__proto__ = Stream.prototype;
*
* CustomStream.prototype._write = function(data){
* //
* };
* ```
*
* @class Stream
* @param {Logger} logger
* @param {Object} options
* @constructor
* @namespace Logger
* @module hexo
*/
var Stream = module.exports = function(logger, options){
options = options || {};
/**
* Hide level.
*
* @property hide
* @type Number
*/
this.hide = options.hide || 7;
var self = this;
logger.on('log', function(data){
if (logger.levels[data.level] < self.hide){
self._write(data);
}
});
};
// Stream.prototype._write = function(data){};
/**
* Set hide level.
*
* @method setHide
* @param {Number} level
* @chainable
*/
Stream.prototype.setHide = function(level){
this.hide = level;
return this;
};