-
Notifications
You must be signed in to change notification settings - Fork 12
/
logfmt.js
41 lines (33 loc) · 1.31 KB
/
logfmt.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
//constructor
function logfmt() {
}
module.exports = logfmt;
var streaming = require('./lib/streaming');
var bodyParser = require('./lib/body_parser');
var bodyParserStream = require('./lib/body_parser_stream');
var logfmtParser = require('./lib/logfmt_parser');
var logger = require('./lib/logger');
var requestLogger = require('./lib/request_logger');
var serializer = require('./lib/stringify');
//Build up logfmt prototype
Object.assign(logfmt.prototype, logger);
Object.assign(logfmt.prototype, streaming);
logfmt.prototype.stringify = serializer.stringify;
logfmt.prototype.parse = logfmtParser.parse;
// Synchronous body parser
logfmt.prototype.bodyParser = function(options) {
options || (options = {});
var mime = options.contentType || "application/logplex-1";
return bodyParser({ contentType: mime, parser: this.parse });
};
// Stream parser
logfmt.prototype.bodyParserStream = function(options) {
options || (options = {});
var mime = options.contentType || "application/logplex-1";
return bodyParserStream({ contentType: mime });
};
logfmt.prototype.requestLogger = function(options, formatter) {
return requestLogger.init(this, options, formatter);
};
logfmt.prototype.requestLogger.commonFormatter = requestLogger.commonFormatter;
Object.assign(logfmt, logfmt.prototype);