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

Implement support for structuredData option (SD-PARAM in RFC 5424). #110

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In addition to the options accepted by the syslog (compliant with [RFC 3164][1]
* __app_name:__ The name of the application (Default: `process.title`).
* __eol:__ The end of line character to be added to the end of the message (Default: Message without modifications).

*Metadata:* Logged as string compiled by [glossy][3].
*Metadata:* Logged as string compiled by [glossy][3]. For RFC5424 messages, you can also include structured data here, inside a `structuredData` object.

## Log Levels
Because syslog only allows a subset of the levels available in [winston][0], levels that do not match will be ignored. Therefore, in order to use `winston-syslog` effectively, you should indicate to [winston][0] that you want to use the syslog levels:
Expand Down
8 changes: 7 additions & 1 deletion lib/winston-syslog.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ class Syslog extends Transport {

const output = info[MESSAGE];

let structuredData = null;
if (info.meta && info.meta.structuredData) {
structuredData = info.meta.structuredData;
}

const syslogMsg = this.producer.produce({
severity: info[LEVEL],
host: this.localhost,
date: new Date(),
message: this.endOfLine ? output + this.endOfLine : output
message: this.endOfLine ? output + this.endOfLine : output,
structuredData: structuredData
});

//
Expand Down
36 changes: 36 additions & 0 deletions test/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,42 @@ vows.describe('syslog messages').addBatch({
'should have appName field set to hello': function (msg) {
assert.equal(msg.appName, 'hello');
transport.close();
},
'setting structuredData information': {
'topic': function () {
const self = this;
server.once('message', function (msg) {
parser.parse(msg, function (d) {
self.callback(null, d);
});
});

transport = new winston.transports.Syslog({
port: PORT,
type: '5424'
});

transport.log({
[LEVEL]: 'debug', [MESSAGE]: 'structured data test',
meta: {
structuredData: {
'exampleSDID@32473': {
sdKey: 'sdValue'
}
}
}
}, function (err) {
assert.ifError(err);
});
},
'should have structuredData field set': function (msg) {
assert.deepEqual(msg.structuredData, {
'exampleSDID@32473': {
sdKey: 'sdValue'
}
});
transport.close();
}
}
}
}
Expand Down