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

Adds support for the RFC5424 structured data field #4

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ There is only one argument available: `--config` (`-c`). This argument is used t
"includeProperties": [],
"messageOnly": false,
"tz": "Etc/UTC",
"newline": false
"newline": false,
"structuredData": "none"
}
```

Expand All @@ -111,6 +112,7 @@ There is only one argument available: `--config` (`-c`). This argument is used t
+ `tz` (string): any [valid timezone string][tzstring] that [moment][moment] will recognize. The timestamp field of the
syslog header will be sent according to this setting.
+ `newline` (boolean): terminate with a newline
+ `structuredData` (string): structured data to send with an RFC5424 message.

[facility]: https://tools.ietf.org/html/rfc3164#section-4.1.1
[tzstring]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Expand Down
2 changes: 1 addition & 1 deletion lib/rfc5424.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function ($options) {
const hostname = data.hostname
const appname = (options.appname !== 'none') ? options.appname : '-'
const msgid = (data.req && data.req.id) ? data.req.id : '-'
const structuredData = '-'
const structuredData = (options.structuredData !== 'none') ? options.structuredData : '-'
Copy link
Member

Choose a reason for hiding this comment

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

Why check for a string'none' instead of a falsy value here? e.g:

const structuredData = options.structuredData  || '-'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how I'd write it normally but instead copied the style you used with appname as I figured you had a reason for defining configuration options that way. Now that you mention it I'm curious why you did it like that?

Copy link
Member

Choose a reason for hiding this comment

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

Oops, it looks like I did do that. It's been so long since I wrote this. I'm fine with you correcting the style.

const header = `<${pri}>${version} ${tstamp} ${hostname} ${appname} ${data.pid} ${msgid} ${structuredData} `
const message = buildMessage(data)
let output = (options.cee && !options.messageOnly) ? `${header}@cee: ${message}` : `${header}${message}`
Expand Down
3 changes: 2 additions & 1 deletion psyslog.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const defaults = {
includeProperties: [],
messageOnly: false,
tz: 'Etc/UTC',
newline: false
newline: false,
structuredData: 'none'
}

const options = Object.assign(defaults, userOptions)
Expand Down