Implement advanced java exception handling using liblognorm error callback#18
Implement advanced java exception handling using liblognorm error callback#18Tiihott wants to merge 19 commits into
Conversation
|
Noticed an error in liblognorm documentations on how the pure json format should be constructed. |
23d2d2c to
a52ce97
Compare
|
Rebased to main |
|
Added exception test for partially invalid rulebase. |
…ackImpl.java. Renamed tests.
…. Removed now obsolete LogMessageMatcher.java.
…mplesJsonCallbackExceptionTest() to loadSamplesJsonTest(). REBASE
8c84421 to
534facc
Compare
|
Rebased to main |
|
|
||
| @Override | ||
| public void invoke(Pointer cookie, String msg, int length) { | ||
| LOGGER.debug("liblognorm: {}", msg); |
| @Override | ||
| public void invoke(Pointer cookie, String msg, int length) { | ||
| errors.add(msg); | ||
| LOGGER.error("liblognorm error: {}", msg); |
| * Method for throwing any received liblognorm error messages as java exception. | ||
| */ | ||
| public void throwOccurredErrors() { | ||
| if (!errors.isEmpty()) { |
There was a problem hiding this comment.
should thrown errors be cleared or are they always so fatal that the object instance is invalid after some occured?
There was a problem hiding this comment.
The rulebase loading method for liblognorm will not return error codes when the rulebase has errors in it, instead it will generate error messages and return 0 indicating that the loading of the rulebase was successful.
By implementing the check for error messages those rulebase errors can be caught as java exceptions.
In my opinion the errors should be handled using fail fast, making the object instance invalid if they occur.
There was a problem hiding this comment.
Here is an example of how the errors can completely break the rulebase while no error codes are returned by liblognorm during normalization.
Message to normalize:
Amount: 1234
Partially invalid rulebase with a typo on last line:
version=2
rule=:%all:rest%
ruletag:Amount: %N:number%
Normalization result with the invalid rulebase is:
{ "all": "Amount: 1234" }
But with a valid rulebase:
version=2
rule=:%all:rest%
rule=tag:Amount: %N:number%
The normalization result is:
{ "N": "1234", "event.tags": [ "tag" ] }
The normalization results are completely different for the same message.
Includes:
Also includes commits from PR #14. Rebase may be needed in this PR after they have been merged to main.
New commits are cf2b6e6 and later.