Skip to content

Commit

Permalink
+ better worker context switch
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Apr 27, 2024
1 parent da046a3 commit 8dec127
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.github.elf4j</groupId>
<artifactId>elf4j-engine</artifactId>
<version>15.2.4</version>
<version>15.2.5</version>
<packaging>jar</packaging>
<name>elf4j-engine</name>
<description>A stand-alone Java log engine implementing the ELF4J (Easy Logging Facade for Java) API</description>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/elf4j/engine/service/writer/GroupWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static List<LogWriterType> getLogWriterTypes(@NonNull LogServiceConfigur
private static @NonNull Runnable withMdcContext(Runnable task) {
Map<String, String> callerContext = MDC.getCopyOfContextMap();
return () -> {
Map<String, String> workerContext = replaceContextWith(callerContext);
Map<String, String> workerContext = switchContextTo(callerContext);
MDC.setContextMap(callerContext);
try {
task.run();
Expand All @@ -131,7 +131,7 @@ private static List<LogWriterType> getLogWriterTypes(@NonNull LogServiceConfigur
};
}

private static Map<String, String> replaceContextWith(Map<String, String> targetContext) {
private static Map<String, String> switchContextTo(Map<String, String> targetContext) {
Map<String, String> replaced = MDC.getCopyOfContextMap();
MDC.setContextMap(targetContext);
return replaced;
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/elf4j/engine/SampleUsageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class SampleUsageTest {
class plainText {
@Test
void declarationsAndLevels() {
logger.log(
"Logger instance is thread-safe so it can be declared and used as a local, instance, or static variable");
logger.log("Logger instance is thread-safe so it can be declared and used as a local, instance, or static"
+ " variable");
logger.log("Default severity level is decided by the logging provider implementation");
Logger trace = logger.atTrace();
trace.log("Explicit severity level is specified by user i.e. TRACE");
Expand All @@ -65,12 +65,13 @@ class textWithArguments {
void lazyAndEagerArgumentsCanBeMixed() {
info.log("Message can have any number of arguments of {} type", Object.class.getTypeName());
info.log(
"Lazy arguments, of {} type, whose values may be {} can be mixed with eager arguments of non-Supplier types",
"Lazy arguments, of {} type, whose values may be {} can be mixed with eager arguments of"
+ " non-Supplier types",
Supplier.class.getTypeName(),
(Supplier) () -> "expensive to compute");
info.atWarn()
.log(
"The Supplier downcast is mandatory per lambda syntax because arguments are declared as generic Object rather than functional interface");
.log("The Supplier downcast is mandatory per lambda syntax because arguments are declared as"
+ " generic Object rather than functional interface");
}
}

Expand All @@ -83,7 +84,8 @@ void asTheFirstArgument() {
logger.atError().log(exception, "Optional log message");
logger.atInfo().log(
exception,
"Exception is always the first argument to a logging method. The {} log message and following arguments work the same way {}.",
"Exception is always the first argument to a logging method. The {} log message and following"
+ " arguments work the same way {}.",
"optional",
(Supplier) () -> "as usual");
}
Expand Down

0 comments on commit 8dec127

Please sign in to comment.