This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format data sent to splunk HEC (#61)
* format data sent to splunk HEC 🐿 v2.7.0 * adding more format hec tests 🐿 v2.7.0
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const formatHEC = ({ level, message, meta = {} } = {}) => { | ||
return message ? Object.assign({}, { level, message }, meta) : Object.assign({}, { level }, meta); | ||
}; | ||
|
||
export default formatHEC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const chai = require('chai'); | ||
chai.should(); | ||
const expect = chai.expect; | ||
|
||
import formatHEC from '../../dist/lib/formatHEC'; | ||
|
||
describe('FormatHEC', () => { | ||
|
||
it('should exist', () => { | ||
formatHEC.should.exist; | ||
}); | ||
|
||
it('should format all data options', () => { | ||
const options = { | ||
level: 'info', | ||
message: 'Hello world', | ||
meta: { event: 'TEST' } | ||
} | ||
|
||
expect(formatHEC(options)).to.deep.equal({ | ||
level: 'info', | ||
message: 'Hello world', | ||
event: 'TEST' | ||
}); | ||
}); | ||
|
||
it('should handle data containing an error', () => { | ||
const err = new Error('This is an error'); | ||
const options = { | ||
level: 'error', | ||
meta: { event: 'TEST_ERROR', err } | ||
} | ||
|
||
expect(formatHEC(options)).to.deep.equal({ | ||
level: 'error', | ||
event: 'TEST_ERROR', err | ||
}); | ||
}); | ||
|
||
it('should handle no meta data ', () => { | ||
const options = { | ||
level: 'info', | ||
message: 'a message' | ||
} | ||
|
||
expect(formatHEC(options)).to.deep.equal({ | ||
level: 'info', | ||
message: 'a message' | ||
}); | ||
}); | ||
|
||
it('should handle no message', () => { | ||
const count = 10; | ||
const options = { | ||
level: 'info', | ||
meta: { event: 'TEST', count } | ||
} | ||
|
||
expect(formatHEC(options)).to.deep.equal({ | ||
level: 'info', | ||
event: 'TEST', | ||
count: 10 | ||
}); | ||
}); | ||
|
||
}); |