-
Notifications
You must be signed in to change notification settings - Fork 45
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
Using custom Lookups for Virtual Properties #36
Comments
You have to extend JacksonJsonLayout.Builder. There are a few ways you can do that:
import com.fasterxml.jackson.databind.ObjectWriter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
@Plugin(name = CustomJacksonJsonLayout.PLUGIN_NAME, category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
public class CustomJacksonJsonLayout extends JacksonJsonLayout {
public static final String PLUGIN_NAME = "CustomJacksonJsonLayout";
protected CustomJacksonJsonLayout(Configuration config, ObjectWriter configuredWriter, ItemSourceFactory itemSourceFactory) {
super(config, configuredWriter, itemSourceFactory);
}
@PluginBuilderFactory
public static CustomJacksonJsonLayout.Builder newBuilder() {
return new CustomJacksonJsonLayout.Builder();
}
public static class Builder extends JacksonJsonLayout.Builder {
@Override
protected ValueResolver createValueResolver() {
return new ValueResolver() {
@Override
public String resolve(String unresolved) {
return "whatever_you_need";
}
@Override
public String resolve(VirtualProperty property) {
return "and_more";
}
};
}
}
}
JacksonJsonLayout.Builder layoutBuilder = new JacksonJsonLayout.Builder() {
@Override
protected ValueResolver createValueResolver() {
return new ValueResolver() {
@Override
public String resolve(String unresolved) {
return "whatever_you_need";
}
@Override
public String resolve(VirtualProperty property) {
return "and_more";
}
};
}
}
.setConfiguration(ctx.getConfiguration())
.withVirtualProperties(
// see Jest and HC SmokeTests for examples
);
|
Sure will do and create a PR for the 3rd option. However, I managed to do this using a custom Lookup plugin in the category of StrLookup.
|
@wageeshagunasena Custom StrLookup plugin makes sense as well! Nice one! |
@wageeshagunasena would you like to create any PRs for this? |
@rfoltyns is Custom StrLookup plugin solution still works with log4j 2.16.0 or 2.17.1 ? Do you have any idea ? |
@manushakaru It does. Have a look at this branch in log42-elasticsearch-examples |
I want to use a custom lookup extended from ValueResolver, for a virtual property to resolve the value. The virtual property is given as in the following configuration.
I see the value resolver for JacksonJsonLayout is set for Log4j2Lookup. How can I set my custom value resolver to do this?
The text was updated successfully, but these errors were encountered: