Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating logstash to v1 #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions logstash.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const jsonStringify = require('fast-safe-stringify');
*/
module.exports = format(info => {
const logstash = {};

if (info.message) {
logstash['@message'] = info.message;
logstash.message = info.message;
delete info.message;
}

Expand All @@ -23,7 +24,12 @@ module.exports = format(info => {
delete info.timestamp;
}

logstash['@fields'] = info;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line will also remove all root level fields, not just level.

if (info.level) {
logstash.level = info.level;
delete info.level;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomasAlabes Thanks and sorry for slow review! Only question is: why are you deleting info.level? This doesn't seem necessary and feels like it could interfere with subsequent formatters that expect to find it? Let me know what you think -- thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem David.
Honestly, I was just following the pattern of the previous code 🤷‍♂️

}

logstash['@version'] = 1;
info[MESSAGE] = jsonStringify(logstash);
return info;
});
22 changes: 10 additions & 12 deletions test/logstash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@ const { MESSAGE } = require('triple-beam');
const TIMESTAMP = Symbol.for('timestamp');

describe('logstash', () => {
it('default { @message, @fields } sets info[MESSAGE]', helpers.assumeFormatted(
it('default { @version, message } sets info[MESSAGE]', helpers.assumeFormatted(
logstash(),
{ level: 'info', message: 'whatever' },
(info, expected) => {
assume(info.level).equals('info');
assume(info.level).equals(undefined);
assume(info.message).equals(undefined);
assume(info[MESSAGE]).equals(JSON.stringify({
'@message': expected.message,
'@fields': {
level: expected.level
}
'message': expected.message,
'level': expected.level,
'@version': 1
}));
}
));

it('with timestamp { @message, @timestamp, @fields } sets info[MESSAGE]', helpers.assumeFormatted(
it('with timestamp { @version, @timestamp, message } sets info[MESSAGE]', helpers.assumeFormatted(
combine(
timestamp({ alias: TIMESTAMP }),
logstash()
),
{ level: 'info', message: 'whatever' },
(info, expected) => {
assume(info.level).equals('info');
assume(info.level).equals(undefined);
assume(info.message).equals(undefined);
assume(info[MESSAGE]).equals(JSON.stringify({
'@message': expected.message,
'message': expected.message,
'@timestamp': info[TIMESTAMP],
'@fields': {
level: expected.level
}
'level': expected.level,
'@version': 1
}));
}
));
Expand Down