This repository was archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Support type definitions for DynamicMdcField Patterns #197
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
52e47ee
- Started to implement dynamicMdcFileTypes feature
cchet 904ff2a
- Added missing setting of dynamicFieldTypes in PoolingGelfMEssageBui…
cchet 42122f7
- Added new model class for addtionalMdcFieldTypes for log4j
cchet da18633
- Renamed test classes to better reflect what they are testing
cchet 0823d75
- Renamed class
cchet d8df6d5
- Removed final usage
cchet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/biz/paluch/logging/gelf/log4j2/GelfDynamicMdcFieldType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package biz.paluch.logging.gelf.log4j2; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.core.config.Configuration; | ||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.config.plugins.PluginAttribute; | ||
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; | ||
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.status.StatusLogger; | ||
import org.apache.logging.log4j.util.Strings; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Configuration for dynamic log fields pulled from MDC. | ||
* | ||
* @author Thomas Herzog | ||
*/ | ||
@Plugin(name = "DynamicMdcFieldTypes", category = "Core", printObject = true) | ||
public class GelfDynamicMdcFieldType { | ||
|
||
private static final Logger LOGGER = StatusLogger.getLogger(); | ||
|
||
private final Pattern pattern; | ||
private final String type; | ||
|
||
public GelfDynamicMdcFieldType(Pattern pattern, String type) { | ||
this.pattern = pattern; | ||
this.type = type; | ||
} | ||
|
||
public Pattern getPattern() { | ||
return pattern; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
@PluginFactory | ||
public static GelfDynamicMdcFieldType createField(@PluginConfiguration final Configuration config, | ||
@PluginAttribute("regex") String regex, | ||
@PluginAttribute("type") String type) { | ||
|
||
Pattern pattern; | ||
if (Strings.isEmpty(regex) || Strings.isEmpty(type)) { | ||
throw new IllegalArgumentException(String.format("regex=%s or type=%s is empty or null", regex, type)); | ||
} | ||
try { | ||
pattern = Pattern.compile(regex); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException(String.format("Regex is invalid: regex=%s", regex), e); | ||
} | ||
|
||
return new GelfDynamicMdcFieldType(pattern, type); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.