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 advanced java exception handling for liblognorm ln_loadSamples() method #16

Open
Tiihott opened this issue Jan 20, 2025 · 2 comments · May be fixed by #18
Open

Implement advanced java exception handling for liblognorm ln_loadSamples() method #16

Tiihott opened this issue Jan 20, 2025 · 2 comments · May be fixed by #18
Assignees
Labels

Comments

@Tiihott
Copy link
Contributor

Tiihott commented Jan 20, 2025

Description
In some cases ln_loadSamples() returns zero (success) even though the loading of the rulebase failed and an error message was logged through liblognorm error logging callback method.
If the broken rulebase is then used for normalization the ln_normalize() method also returns zero (success), but instead of generating a successfully normalized message the method generates json that contains further error details in normalized form.

The error message logged by the callback method must be used to trigger an exception in the java code, preventing the usage of broken rulebase for normalization.

An example rulebase that is missing version=2 line from the beginning, which will trigger the error:

rule=:%[ {"type":"date-rfc3164", "name":"date"},
         {"type":"literal", "text:" "},
         {"type":"char-to", "name":"host", "extradata":":"},
         {"type":"literal", "text:": no longer listening on "},
         {"type":"ipv4", "name":"ip"},
         {"type":"literal", "text:"#"},
         {"type":"number", "name":"port"}
        ]%
@Tiihott Tiihott self-assigned this Jan 20, 2025
@Tiihott
Copy link
Contributor Author

Tiihott commented Jan 20, 2025

By encapsulating ErrorCallbackImpl inside the java class that is interacting with the liblognorm library through JNA, it is possible to keep track of errors occurring inside liblognorm library for java exception handling.

@Tiihott
Copy link
Contributor Author

Tiihott commented Feb 13, 2025

Version 2 rulebase also behaves similarly like version 1 rulebase, the ln_loadSamples() method does not return error codes when there is an invalid rule included in the rulebase. The method does still generate error messages through the error callback, which will allow catching the errors as exceptions in java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant