Commit 421d2f1b authored by Ppchelko's avatar Ppchelko Committed by Petr Pchelko
Browse files

Make the NamedLevel logger a raw objectmode stream

parent d3fc15b9
......@@ -147,6 +147,8 @@ logging:
sampled_levels:
'trace/webrequest': 0.2
streams:
- type: stdout # log to stdout
named_levels: true # emit log level name instead of index. e.g. INFO vs 30
# Use gelf-stream -> logstash
- type: gelf
host: logstash1003.eqiad.wmnet
......
'use strict';
const Writable = require('stream').Writable;
const bunyan = require('bunyan');
const gelfStream = require('gelf-stream');
const syslogStream = require('bunyan-syslog-udp');
......@@ -12,15 +13,23 @@ function extractSimpleLevel(levelPath) {
return typeof levelPath === 'string' && levelPath.split('/')[0];
}
function NamedLevelStdout() {
return {
write: (entry) => {
// Kind of inefficient approach
var logObject = JSON.parse(entry);
logObject.level = bunyan.nameFromLevel[logObject.level].toUpperCase();
process.stdout.write(JSON.stringify(logObject) + '\n');
}
};
class NamedLevelStdout extends Writable {
constructor(downstream, options = {}) {
super(Object.assign(options, { objectMode: true }));
this.downstream = downstream;
}
_write(logEntry, encoding, callback) {
logEntry.level = bunyan.nameFromLevel[logEntry.level].toUpperCase();
this.downstream.write(
JSON.stringify(logEntry) + '\n',
encoding,
callback
);
}
destroy() {
super.destroy();
this.downstream.destroy();
}
}
const streamConverter = {
......@@ -52,16 +61,18 @@ const streamConverter = {
};
},
stdout(stream, conf) {
return {
stream: process.stdout,
level: stream.level || conf.level
};
},
namedstdout(stream, conf) {
return {
stream: NamedLevelStdout(),
level: stream.level || conf.level
};
if ( stream.named_levels ) {
return {
type: 'raw',
stream: new NamedLevelStdout(process.stdout),
level: stream.level || conf.level
};
} else {
return {
stream: process.stdout,
level: stream.level || conf.level
};
}
},
debug(stream, conf) {
try {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment