This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow data type specification for MDC/additional fields #59
- Loading branch information
Showing
30 changed files
with
580 additions
and
188 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
90 changes: 90 additions & 0 deletions
90
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
This file contains 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,90 @@ | ||
package biz.paluch.logging.gelf.intern; | ||
|
||
import biz.paluch.logging.gelf.DynamicMdcMessageField; | ||
import biz.paluch.logging.gelf.GelfMessageAssembler; | ||
import biz.paluch.logging.gelf.MdcMessageField; | ||
import biz.paluch.logging.gelf.StaticMessageField; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
*/ | ||
public class ConfigurationSupport { | ||
public static final String MULTI_VALUE_DELIMITTER = ","; | ||
public static final char EQ = '='; | ||
|
||
private ConfigurationSupport() { | ||
|
||
} | ||
|
||
/** | ||
* Set the additional (static) fields. | ||
* | ||
* @param spec field=value,field1=value1, ... | ||
* @param gelfMessageAssembler the Gelf message assembler to apply the configuration | ||
*/ | ||
public static void setAdditionalFields(String spec, GelfMessageAssembler gelfMessageAssembler) { | ||
if (null != spec) { | ||
String[] properties = spec.split(MULTI_VALUE_DELIMITTER); | ||
|
||
for (String field : properties) { | ||
final int index = field.indexOf(EQ); | ||
if (-1 == index) { | ||
continue; | ||
} | ||
gelfMessageAssembler.addField(new StaticMessageField(field.substring(0, index), field.substring(index + 1))); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set the MDC fields. | ||
* | ||
* @param spec field, field2, field3 | ||
* @param gelfMessageAssembler the Gelf message assembler to apply the configuration | ||
*/ | ||
public static void setMdcFields(String spec, GelfMessageAssembler gelfMessageAssembler) { | ||
if (null != spec) { | ||
String[] fields = spec.split(MULTI_VALUE_DELIMITTER); | ||
|
||
for (String field : fields) { | ||
gelfMessageAssembler.addField(new MdcMessageField(field.trim(), field.trim())); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set the dynamic MDC fields. | ||
* | ||
* @param spec field, .*FieldSuffix, fieldPrefix.* | ||
* @param gelfMessageAssembler | ||
*/ | ||
public static void setDynamicMdcFields(String spec, GelfMessageAssembler gelfMessageAssembler) { | ||
if (null != spec) { | ||
String[] fields = spec.split(MULTI_VALUE_DELIMITTER); | ||
|
||
for (String field : fields) { | ||
gelfMessageAssembler.addField(new DynamicMdcMessageField(field.trim())); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set the additional field types. | ||
* | ||
* @param spec field=String,field1=Double, ... See {@link GelfMessage} for supported types. | ||
* @param gelfMessageAssembler the Gelf message assembler to apply the configuration | ||
*/ | ||
public static void setAdditionalFieldTypes(String spec, GelfMessageAssembler gelfMessageAssembler) { | ||
if (null != spec) { | ||
String[] properties = spec.split(MULTI_VALUE_DELIMITTER); | ||
|
||
for (String field : properties) { | ||
final int index = field.indexOf(EQ); | ||
if (-1 != index) { | ||
gelfMessageAssembler.setAdditionalFieldType(field.substring(0, index), field.substring(index + 1)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.