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

Add another method for adding static field to GelfEncoder #80

Closed
vavrtom opened this issue Feb 8, 2022 · 2 comments
Closed

Add another method for adding static field to GelfEncoder #80

vavrtom opened this issue Feb 8, 2022 · 2 comments
Milestone

Comments

@vavrtom
Copy link

vavrtom commented Feb 8, 2022

Is your feature request related to a problem? Please describe.
If I have two objects containing key (String) and value (String/Object) and I want to add them as static field to GelfEncoder I have to create new string in key:value format and pass it to method addStaticField(String staticField), where key and value are parsed from the staticField string.

Describe the solution you'd like
Method addStaticField(String key, String value) or addStaticField(String key, Object value) could be introduced in GelfEncoder, then key and value can be directly passed to method without creating/parsing of the string.

Describe alternatives you've considered
Create a string in key:value format and pass the string to method addStaticField(String staticField).

@osiegmar
Copy link
Owner

osiegmar commented Feb 8, 2022

I don't exactly understand your use case. If you're using the API (not the XML configuration) you could easily use a custom field mapper for this. See #78 for example. Doing so programmatically is even simpler:

GelfEncoder e = new GelfEncoder();
e.addFieldMapper((event, valueHandler) -> valueHandler.accept("MY_KEY", "MY_VALUE"));

The static fields are a very basic (and limited) concept mainly for XML based configuration.

@vavrtom
Copy link
Author

vavrtom commented Feb 9, 2022

Yes, I am using the API. In versions <=3.0.0 I was using the setStaticFields(Map<String, Object> staticFields) method in GelfEncoder initialization.

I did not want to use field mapper, because then all static fields keys are validated in the addField() method for each message, which seems redundant to me (keys will be the same). When addStaticField(String staticField) method is used, key validation is performed only during adding static field.

I just thought it could be useful for someone who was using setStaticFields() method in <=3.0.0 versions (reintroducing setStaticFields() could be another option).

If you think, it is not worth it, then issue can be closed. I am perfectly fine with the existing methods for setting static fields.

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

No branches or pull requests

2 participants