Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions jul/src/main/java/echopraxia/jul/JULCoreLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -125,11 +123,6 @@ public String getName() {
return newLogger(this.condition.and(condition));
}

@Override
public @NotNull JULCoreLogger withExecutor(@NotNull Executor executor) {
return newLogger(executor);
}

@Override
public @NotNull JULCoreLogger withFQCN(@NotNull String fqcn) {
return newLogger(fqcn);
Expand Down Expand Up @@ -405,93 +398,6 @@ public void log(@Nullable String message, @NotNull Function<FB, FieldBuilderResu
};
}

@Override
public <FB> void asyncLog(
@NotNull Level level, @NotNull Consumer<LoggerHandle<FB>> consumer, @NotNull FB builder) {
if (logger.isLoggable(convertLevel(level))) {
Runnable threadLocalRunnable = threadContextFunction.get();
runAsyncLog(
() -> {
threadLocalRunnable.run();
consumer.accept(newHandle(level, builder, this));
});
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Condition c,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isLoggable(convertLevel(level))) {
Runnable threadLocalRunnable = threadContextFunction.get();
runAsyncLog(
() -> {
threadLocalRunnable.run();
final LoggerHandle<FB> loggerHandle = newHandle(level, c, builder, this);
consumer.accept(loggerHandle);
});
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isLoggable(convertLevel(level))) {
Runnable threadLocalRunnable = threadContextFunction.get();
runAsyncLog(
() -> {
threadLocalRunnable.run();
final LoggerHandle<FB> loggerHandle = newHandle(level, builder, this);
consumer.accept(loggerHandle);
});
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Condition c,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isLoggable(convertLevel(level))) {
Runnable threadLocalRunnable = threadContextFunction.get();
runAsyncLog(
() -> {
threadLocalRunnable.run();
final LoggerHandle<FB> loggerHandle = newHandle(level, c, builder, this);
consumer.accept(loggerHandle);
});
}
}

protected void runAsyncLog(Runnable runnable) {
// exceptionally is available in JDK 1.8, we can't use exceptionallyAsync as it's 12 only
CompletableFuture.runAsync(runnable, executor)
.exceptionally(
e -> {
// Usually we get to this point when you have thread local dependent code in your
// logger.withContext() block, and your executor doesn't have those thread locals
// so you NPE.
//
// We need to log this error, but since it could be part of the logger context
// that is causing this error, we can't log the error with the same logger.
//
// Fallback to the underlying SLF4J logger to render it.
final Throwable cause = e.getCause(); // strip the CompletionException
logger.log(
java.util.logging.Level.SEVERE,
"Uncaught exception when running asyncLog",
cause);
return null;
});
}

@NotNull
private <FB> LoggerHandle<FB> newHandle(
@NotNull Level level, @NotNull FB builder, JULCoreLogger callerLogger) {
Expand Down
96 changes: 0 additions & 96 deletions log4j/src/main/java/echopraxia/log4j/Log4JCoreLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.logging.log4j.Logger;
Expand All @@ -23,7 +22,6 @@
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.spi.ExtendedLogger;
import org.apache.logging.log4j.util.StackLocatorUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -135,11 +133,6 @@ public String getName() {
return newLogger(this.condition.and(condition));
}

@Override
public @NotNull Log4JCoreLogger withExecutor(@NotNull Executor executor) {
return new Log4JCoreLogger(fqcn, logger, context, condition, executor, threadContextFunction);
}

@Override
public @NotNull Log4JCoreLogger withFQCN(@NotNull String fqcn) {
return new Log4JCoreLogger(fqcn, logger, context, condition, executor, threadContextFunction);
Expand Down Expand Up @@ -436,95 +429,6 @@ public void log(
};
}

@Override
public <FB> void asyncLog(
@NotNull Level level, @NotNull Consumer<LoggerHandle<FB>> consumer, @NotNull FB builder) {
if (logger.isEnabled(convertLevel(level), context.getMarker())) {
StackTraceElement location = includeLocation() ? StackLocatorUtil.calcLocation(fqcn) : null;
Runnable threadLocalRunnable = threadContextFunction.get();
Runnable runnable =
createRunnable(
location, threadLocalRunnable, context, level, condition, consumer, builder);
runAsyncLog(runnable);
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Condition c,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isEnabled(convertLevel(level), context.getMarker())) {
StackTraceElement location = includeLocation() ? StackLocatorUtil.calcLocation(fqcn) : null;
Runnable threadLocalRunnable = threadContextFunction.get();
Runnable runnable =
createRunnable(
location, threadLocalRunnable, context, level, condition.and(c), consumer, builder);
runAsyncLog(runnable);
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isEnabled(convertLevel(level), context.getMarker())) {
StackTraceElement location = includeLocation() ? StackLocatorUtil.calcLocation(fqcn) : null;
Runnable threadLocalRunnable = threadContextFunction.get();
Runnable runnable =
createRunnable(
location,
threadLocalRunnable,
context.withFields(extraFields),
level,
condition,
consumer,
builder);
runAsyncLog(runnable);
}
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Condition c,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
if (logger.isEnabled(convertLevel(level), context.getMarker())) {
StackTraceElement location = includeLocation() ? StackLocatorUtil.calcLocation(fqcn) : null;
Runnable threadLocalRunnable = threadContextFunction.get();
Runnable runnable =
createRunnable(
location,
threadLocalRunnable,
context.withFields(extraFields),
level,
condition.and(c),
consumer,
builder);
runAsyncLog(runnable);
}
}

private <FB> Runnable createRunnable(
@Nullable StackTraceElement location,
Runnable threadLocalRunnable,
Context extraContext,
Level level,
Condition c,
Consumer<LoggerHandle<FB>> consumer,
FB builder) {
return () -> {
threadLocalRunnable.run();
final LoggerHandle<FB> loggerHandle = newHandle(location, extraContext, level, c, builder);
consumer.accept(loggerHandle);
};
}

protected <FB> LoggerHandle<FB> newHandle(
@Nullable StackTraceElement location,
@NotNull Context extraContext,
Expand Down
69 changes: 0 additions & 69 deletions logging/src/main/java/echopraxia/logging/spi/CoreLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import echopraxia.logging.api.LoggerHandle;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -104,15 +102,6 @@ CoreLogger withThreadContext(
@NotNull
CoreLogger withCondition(@NotNull Condition condition);

/**
* Returns a logger with the given executor for asynchronous logging.
*
* @param executor the executor to use.
* @return the core logger with the executor applied.
*/
@NotNull
CoreLogger withExecutor(@NotNull Executor executor);

/**
* Returns a logger with the given fully qualified caller name.
*
Expand Down Expand Up @@ -281,62 +270,4 @@ <FB> void log(
*/
@NotNull
<FB> LoggerHandle<FB> logHandle(@NotNull Level level, @NotNull FB builder);

/**
* Logs a statement asynchronously using an executor.
*
* @param <FB> the field builder type
* @param level the logging level
* @param consumer the consumer of the logger handle
* @param builder the field builder.
*/
<FB> void asyncLog(
@NotNull Level level, @NotNull Consumer<LoggerHandle<FB>> consumer, @NotNull FB builder);

/**
* Logs a statement asynchronously using an executor and the given condition.
*
* @param <FB> the field builder type
* @param level the logging level
* @param condition the condition
* @param consumer the consumer of the logger handle
* @param builder the field builder.
*/
<FB> void asyncLog(
@NotNull Level level,
@NotNull Condition condition,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder);

/**
* Logs a statement asynchronously using an executor.
*
* @param <FB> the field builder type
* @param level the logging level
* @param extraFields fields to be added to the logger context
* @param consumer the consumer of the logger handle
* @param builder the field builder.
*/
<FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder);

/**
* Logs a statement asynchronously using an executor and the given condition.
*
* @param <FB> the field builder type
* @param level the logging level
* @param extraFields fields to be added to the logger context
* @param condition the condition
* @param consumer the consumer of the logger handle
* @param builder the field builder.
*/
<FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Condition condition,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import echopraxia.logging.api.LoggerHandle;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -71,12 +69,6 @@ public CoreLogger withCondition(@NotNull Condition condition) {
return core.withCondition(condition);
}

@Override
@NotNull
public CoreLogger withExecutor(@NotNull Executor executor) {
return core.withExecutor(executor);
}

@Override
@NotNull
public CoreLogger withFQCN(@NotNull String fqcn) {
Expand Down Expand Up @@ -176,38 +168,4 @@ public <FB> void log(
public <FB> LoggerHandle<FB> logHandle(@NotNull Level level, @NotNull FB builder) {
return core.logHandle(level, builder);
}

@Override
public <FB> void asyncLog(
@NotNull Level level, @NotNull Consumer<LoggerHandle<FB>> consumer, @NotNull FB builder) {
core.asyncLog(level, consumer, builder);
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Condition condition,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
core.asyncLog(level, condition, consumer, builder);
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
core.asyncLog(level, extraFields, consumer, builder);
}

@Override
public <FB> void asyncLog(
@NotNull Level level,
@NotNull Supplier<List<Field>> extraFields,
@NotNull Condition condition,
@NotNull Consumer<LoggerHandle<FB>> consumer,
@NotNull FB builder) {
core.asyncLog(level, extraFields, condition, consumer, builder);
}
}
Loading
Loading