-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
90 additions
and
15 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
34 changes: 34 additions & 0 deletions
34
src/main/java/elf4j/engine/service/pattern/ContextElement.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,34 @@ | ||
package elf4j.engine.service.pattern; | ||
|
||
import elf4j.engine.service.LogEvent; | ||
import java.util.NoSuchElementException; | ||
import lombok.NonNull; | ||
import org.slf4j.MDC; | ||
|
||
public class ContextElement implements PatternElement { | ||
final String key; | ||
|
||
public ContextElement(String key) { | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public boolean includeCallerDetail() { | ||
return false; | ||
} | ||
|
||
public static @NonNull ContextElement from(String patternSegment) { | ||
return new ContextElement(PatternElements.getPatternElementDisplayOption(patternSegment) | ||
.orElseThrow(() -> new NoSuchElementException("No key configured in 'context' pattern element"))); | ||
} | ||
/** | ||
* | ||
* @param logEvent entire log content data source to render | ||
* @param target logging text aggregator of the final log message | ||
*/ | ||
@Override | ||
public void render(LogEvent logEvent, @NonNull StringBuilder target) { | ||
String value = MDC.get(key); | ||
target.append(value == null ? "" : value); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.slf4j; | ||
|
||
import org.slf4j.helpers.BasicMDCAdapter; | ||
import org.slf4j.helpers.NOPMDCAdapter; | ||
import org.slf4j.spi.MDCAdapter; | ||
|
||
public class MdcAdapterInitializer { | ||
private MdcAdapterInitializer() {} | ||
|
||
public static void initialize() { | ||
MDCAdapter byOtherSlf4jProvider = MDC.mdcAdapter; | ||
if (byOtherSlf4jProvider == null || byOtherSlf4jProvider instanceof NOPMDCAdapter) { | ||
MDC.mdcAdapter = new BasicMDCAdapter(); | ||
} | ||
} | ||
} |
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