Skip to content

Commit

Permalink
+ elf4j version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Nov 4, 2023
1 parent 313edff commit 61cbf9b
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 112 deletions.
4 changes: 2 additions & 2 deletions 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>14.0.3</version>
<version>15.0.0</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 Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>io.github.elf4j</groupId>
<artifactId>elf4j</artifactId>
<version>3.1.0</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>io.github.q3769</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

import elf4j.Level;
import elf4j.Logger;
import elf4j.engine.service.EventingLogService;
import elf4j.engine.service.LogService;
import elf4j.engine.service.LogServiceManager;
import elf4j.engine.service.EventingNativeLoggerService;
import elf4j.engine.service.NativeLogServiceManager;
import elf4j.engine.service.NativeLoggerService;
import elf4j.engine.service.configuration.LogServiceConfiguration;
import elf4j.engine.service.util.StackTraceUtils;
import elf4j.spi.LoggerFactory;
import elf4j.spi.LogServiceProvider;
import java.util.EnumSet;
import java.util.Map;
import java.util.Properties;
Expand All @@ -46,7 +46,7 @@
/**
*
*/
public class NativeLoggerFactory implements LoggerFactory, LogServiceManager.Refreshable {
public class NativeLogServiceProvider implements LogServiceProvider, NativeLogServiceManager.Refreshable {
private static final Level DEFAULT_LOGGER_SEVERITY_LEVEL = Level.INFO;
/**
* Made injectable for extensions other than this native ELF4J implementation
Expand All @@ -69,31 +69,31 @@ public class NativeLoggerFactory implements LoggerFactory, LogServiceManager.Ref
private final Class<?> serviceAccessClass;

@NonNull
private final LogServiceFactory logServiceFactory;
private final NativeLogServiceProvider.NativeLoggerServiceFactory nativeLoggerServiceFactory;

/**
* Default constructor required by {@link java.util.ServiceLoader}
*/
public NativeLoggerFactory() {
public NativeLogServiceProvider() {
this(Logger.class);
}

/**
* @param serviceAccessClass the class or interface that the API client application calls first to a logger
* instance
*/
public NativeLoggerFactory(@NonNull Class<?> serviceAccessClass) {
this(DEFAULT_LOGGER_SEVERITY_LEVEL, serviceAccessClass, new ConfiguredLogServiceFactory());
public NativeLogServiceProvider(@NonNull Class<?> serviceAccessClass) {
this(DEFAULT_LOGGER_SEVERITY_LEVEL, serviceAccessClass, new ConfiguredNativeLoggerServiceFactory());
}

NativeLoggerFactory(
NativeLogServiceProvider(
@NonNull Level defaultLoggerLevel,
@NonNull Class<?> serviceAccessClass,
@NonNull LogServiceFactory logServiceFactory) {
@NonNull NativeLogServiceProvider.NativeLoggerServiceFactory nativeLoggerServiceFactory) {
this.defaultLoggerLevel = defaultLoggerLevel;
this.serviceAccessClass = serviceAccessClass;
this.logServiceFactory = logServiceFactory;
LogServiceManager.INSTANCE.register(this);
this.nativeLoggerServiceFactory = nativeLoggerServiceFactory;
NativeLogServiceManager.INSTANCE.register(this);
}

/**
Expand All @@ -110,51 +110,51 @@ public NativeLogger logger() {

@Override
public void refresh(@Nullable Properties properties) {
logServiceFactory.reset(properties);
nativeLoggerServiceFactory.reset(properties);
}

@Override
public void refresh() {
logServiceFactory.reload();
nativeLoggerServiceFactory.reload();
}

@NonNull
LogService getLogService() {
return logServiceFactory.getLogService();
NativeLoggerService getLogService() {
return nativeLoggerServiceFactory.getLogService();
}

NativeLogger getLogger(Level level, String declaringClassName) {
return nativeLoggers.get(level).computeIfAbsent(declaringClassName, k -> new NativeLogger(k, level, this));
}

interface LogServiceFactory {
LogService getLogService();
interface NativeLoggerServiceFactory {
NativeLoggerService getLogService();

void reload();

void reset(Properties properties);
}

static class ConfiguredLogServiceFactory implements LogServiceFactory {
private LogService logService;
static class ConfiguredNativeLoggerServiceFactory implements NativeLoggerServiceFactory {
private NativeLoggerService nativeLoggerService;

private ConfiguredLogServiceFactory() {
logService = new EventingLogService(LogServiceConfiguration.byLoading());
private ConfiguredNativeLoggerServiceFactory() {
nativeLoggerService = new EventingNativeLoggerService(LogServiceConfiguration.byLoading());
}

@Override
public LogService getLogService() {
return logService;
public NativeLoggerService getLogService() {
return nativeLoggerService;
}

@Override
public void reload() {
logService = new EventingLogService(LogServiceConfiguration.byLoading());
nativeLoggerService = new EventingNativeLoggerService(LogServiceConfiguration.byLoading());
}

@Override
public void reset(Properties properties) {
logService = new EventingLogService(LogServiceConfiguration.bySetting(properties));
nativeLoggerService = new EventingNativeLoggerService(LogServiceConfiguration.bySetting(properties));
}
}
}
18 changes: 9 additions & 9 deletions src/main/java/elf4j/engine/NativeLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import elf4j.Level;
import elf4j.Logger;
import elf4j.engine.service.LogService;
import elf4j.engine.service.NativeLoggerService;
import javax.annotation.concurrent.ThreadSafe;
import lombok.NonNull;

Expand Down Expand Up @@ -56,28 +56,28 @@ public class NativeLogger implements Logger {
private final @NonNull String declaringClassName;

private final @NonNull Level level;
private final @NonNull NativeLoggerFactory nativeLoggerFactory;
private final @NonNull NativeLogServiceProvider nativeLogServiceProvider;

/**
* Constructor only meant to be used by {@link NativeLoggerFactory} and this class itself
* Constructor only meant to be used by {@link NativeLogServiceProvider} and this class itself
*
* @param declaringClassName name of the declaring class that requested this instance via the
* {@link Logger#instance()} method
* @param level severity level of this logger instance
* @param nativeLoggerFactory log service access point from this instance, not reloadable
* @param nativeLogServiceProvider log service access point from this instance, not reloadable
*/
public NativeLogger(
@NonNull String declaringClassName,
@NonNull Level level,
@NonNull NativeLoggerFactory nativeLoggerFactory) {
@NonNull NativeLogServiceProvider nativeLogServiceProvider) {
this.declaringClassName = declaringClassName;
this.level = level;
this.nativeLoggerFactory = nativeLoggerFactory;
this.nativeLogServiceProvider = nativeLogServiceProvider;
}

@Override
public NativeLogger atLevel(Level level) {
return this.level == level ? this : this.nativeLoggerFactory.getLogger(level, this.declaringClassName);
return this.level == level ? this : this.nativeLogServiceProvider.getLogger(level, this.declaringClassName);
}

@Override
Expand Down Expand Up @@ -118,8 +118,8 @@ public void log(Throwable throwable, String message, Object... arguments) {
/**
* @return directly callable log service, useful for other logging frameworks to use this engine
*/
public LogService getLogService() {
return this.nativeLoggerFactory.getLogService();
public NativeLoggerService getLogService() {
return this.nativeLogServiceProvider.getLogService();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
/**
* converts a log request into an event for async processing
*/
public class EventingLogService implements LogService {
public class EventingNativeLoggerService implements NativeLoggerService {
private final boolean noop;
private final LogWriter logWriter;
private final LoggerOutputLevelThreshold loggerOutputLevelThreshold;
private final Map<NativeLogger, Boolean> loggerEnabled = new ConcurrentHashMap<>();

public EventingLogService(@NonNull LogServiceConfiguration logServiceConfiguration) {
public EventingNativeLoggerService(@NonNull LogServiceConfiguration logServiceConfiguration) {
if (logServiceConfiguration.isAbsent() || logServiceConfiguration.isTrue("noop")) {
noop = true;
IeLogger.WARN.log("No-op per configuration {}", logServiceConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
*/
@ToString
public enum LogServiceManager {
public enum NativeLogServiceManager {
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
*
*/
public interface LogService extends PerformanceSensitive {
public interface NativeLoggerService extends PerformanceSensitive {
/**
* @param nativeLogger to check for enablement
* @return true if the logger's level is at or above configured threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package elf4j.engine.service.util;

import elf4j.engine.service.LogServiceManager;
import elf4j.engine.service.NativeLogServiceManager;
import elf4j.util.IeLogger;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestPlan;
Expand All @@ -38,6 +38,6 @@ public class Elf4jPostTestProcessor implements TestExecutionListener {
@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
IeLogger.INFO.log("Shutting down elf4j service after finishing {}", testPlan);
LogServiceManager.INSTANCE.shutdown();
NativeLogServiceManager.INSTANCE.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import conseq4j.execute.ConseqExecutor;
import elf4j.Level;
import elf4j.engine.service.LogEvent;
import elf4j.engine.service.LogServiceManager;
import elf4j.engine.service.NativeLogServiceManager;
import elf4j.engine.service.configuration.LogServiceConfiguration;
import elf4j.util.IeLogger;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -44,7 +44,7 @@
* order; meanwhile, logs from the same caller thread will arrive sequentially in the same order as they are called in
* the original thread.
*/
public class ConseqWriterGroup implements LogWriter, LogServiceManager.Stoppable {
public class ConseqWriterGroup implements LogWriter, NativeLogServiceManager.Stoppable {
private static final int DEFAULT_CONCURRENCY = Runtime.getRuntime().availableProcessors();
private final List<LogWriter> writers;
private final ConseqExecutor conseqExecutor;
Expand All @@ -57,7 +57,7 @@ private ConseqWriterGroup(@NonNull List<LogWriter> writers, ConseqExecutor conse
this.writers = writers;
this.conseqExecutor = conseqExecutor;
IeLogger.INFO.log("{} service writer(s) in {}", writers.size(), this);
LogServiceManager.INSTANCE.register(this);
NativeLogServiceManager.INSTANCE.register(this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/elf4j/engine/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package elf4j.engine;

import elf4j.Logger;
import elf4j.engine.service.LogServiceManager;
import elf4j.engine.service.NativeLogServiceManager;
import java.util.function.Supplier;

public class Main {
Expand Down Expand Up @@ -54,6 +54,6 @@ public static void main(String[] args) {
.atTrace()
.atDebug()
.log("Not a practical example but now the severity level is DEBUG");
LogServiceManager.INSTANCE.shutdown();
NativeLogServiceManager.INSTANCE.shutdown();
}
}
Loading

0 comments on commit 61cbf9b

Please sign in to comment.