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 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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.

By default, syslog messages are produced by [glossy][3], but you can override that behavior by providing a
custom **Producer** instance via the **customProducer** setting.
Expand Down
8 changes: 7 additions & 1 deletion lib/winston-syslog.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,17 @@ class Syslog extends Transport {
level = level === 'warn' ? 'warning' : level;
const output = info[MESSAGE];

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

const syslogMsg = this.producer.produce({
severity: 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 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