Skip to content

Commit

Permalink
+ no additional thread switch for sole writer
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Oct 14, 2023
1 parent f7d39dd commit d377330
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 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>13.0.8</version>
<version>13.0.9</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
17 changes: 8 additions & 9 deletions src/main/java/elf4j/engine/service/writer/ConseqWriterGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ConseqWriterGroup implements LogWriter, LogServiceManager.Stoppable
private Level minimumLevel;
@ToString.Exclude private Boolean includeCallerDetail;

private ConseqWriterGroup(List<LogWriter> writers, ConseqExecutor conseqExecutor) {
private ConseqWriterGroup(@NonNull List<LogWriter> writers, ConseqExecutor conseqExecutor) {
this.writers = writers;
this.conseqExecutor = conseqExecutor;
IeLogger.INFO.log("{} service writer(s) in {}", writers.size(), this);
Expand Down Expand Up @@ -118,14 +118,13 @@ public Level getMinimumOutputLevel() {

@Override
public void write(@NonNull LogEvent logEvent) {
long callerThreadId = logEvent.getCallerThread().getId();
if (writers.size() == 1) {
LogWriter soleWriter = writers.get(0);
conseqExecutor.execute(() -> soleWriter.write(logEvent), callerThreadId);
return;
}
conseqExecutor.execute(() -> writers.stream().parallel().forEach(writer -> writer.write(logEvent)),
callerThreadId);
conseqExecutor.execute(() -> {
if (writers.size() == 1) {
writers.get(0).write(logEvent);
return;
}
writers.stream().parallel().forEach(writer -> writer.write(logEvent));
}, logEvent.getCallerThread().getId());
}

@Override
Expand Down

0 comments on commit d377330

Please sign in to comment.