A Logger component, in addition to the message, log level and category section (which I have included in the Global Configuration section) must have, with Huong Dan Java Logger, I’ll add another section related to overriding the values of Category and Correlation Id that we configured in the Global Configuration section. Whether overriding or not is optional, due to user needs. The value of these cells, by default, will be the value from the Global Configuration section.
First, we need to rename the method to be annotated with the @Processor annotation and delete the current argument of this method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
package com.huongdanjava.hdjlogger; import org.mule.api.annotations.Category; import org.mule.api.annotations.Config; import org.mule.api.annotations.Connector; import org.mule.api.annotations.Processor; import com.huongdanjava.hdjlogger.config.ConnectorConfig; @Connector(name="huong-dan-java-logger-component", friendlyName="Huong Dan Java Logger") @Category(name = "org.mule.tooling.category.core", description = "Components") public class HuongDanJavaLoggerComponentConnector { @Config ConnectorConfig config; @Processor public String log() { /* * MESSAGE PROCESSOR CODE GOES HERE */ return config.getCorrelationId(); } public ConnectorConfig getConfig() { return config; } public void setConfig(ConnectorConfig config) { this.config = config; } } |
This method name will be the name that appears in the Operation section of the main configuration of our connector.
Now we can add the configuration as we said above:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package com.huongdanjava.hdjlogger; import org.mule.api.annotations.Category; import org.mule.api.annotations.Config; import org.mule.api.annotations.Connector; import org.mule.api.annotations.Processor; import org.mule.api.annotations.display.FriendlyName; import org.mule.api.annotations.display.Placement; import org.mule.api.annotations.param.Default; import org.mule.api.annotations.param.Optional; import com.huongdanjava.hdjlogger.config.ConnectorConfig; import com.huongdanjava.hdjlogger.constant.LoggingLevel; import com.huongdanjava.hdjlogger.constant.Text; @Connector(name="huong-dan-java-logger-component", friendlyName="Huong Dan Java Logger") @Category(name = "org.mule.tooling.category.core", description = "Components") public class HuongDanJavaLoggerComponentConnector { @Config ConnectorConfig config; @Processor public String log( @Placement(group = Text.GENERIC, order = 1) @Optional String message, @Placement(group = Text.GENERIC, order = 2) @Default("INFO") @FriendlyName(Text.LEVEL) LoggingLevel loggingLevel, @Placement(group = Text.OVERRIDE, order = 1) @Optional @FriendlyName(Text.OVVERIDE_CORRELATION_ID) String globalCorrelationIdOverride, @Placement(group = Text.OVERRIDE, order = 2) @Optional @FriendlyName(Text.OVVERIDE_CATEGORY) String globalCategoryOverride) { return config.getCorrelationId(); } public ConnectorConfig getConfig() { return config; } public void setConfig(ConnectorConfig config) { this.config = config; } } |
Here, I added a new LoggingLevel class to define the log level for the Huong Dan Java Logger.
1 2 3 4 5 |
package com.huongdanjava.hdjlogger.constant; public enum LoggingLevel { ERROR, WARN, INFO, DEBUG, TRACE } |
And the Text class is also updated with some new texts:
1 2 3 4 5 6 7 8 9 10 11 |
package com.huongdanjava.hdjlogger.constant; public class Text { public static final String GENERIC = "Generic"; public static final String CORRELATION_ID = "Correlation Id"; public static final String LEVEL = "Level"; public static final String OVERRIDE = "Global Configuration<span class="x x-first x-last"> Override</span>"; public static final String OVVERIDE_CORRELATION_ID = "Corellation Id"; public static final String OVVERIDE_CATEGORY = "Category"; } |
Result:
At this point, we have completed the UI for the main configuration of Huong Dan Java Logger.