Skip to content

Commit

Permalink
+ internal rename
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Oct 28, 2023
1 parent 592ad39 commit d5d8d7e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
11 changes: 10 additions & 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.9</version>
<version>13.0.10</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 @@ -219,6 +219,15 @@
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
<executions>
<execution>
<id>spotless-apply-id</id>
<phase>process-sources</phase>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<java>
<palantirJavaFormat>
Expand Down
40 changes: 21 additions & 19 deletions src/main/java/elf4j/engine/NativeLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,44 @@
@ThreadSafe
public class NativeLogger implements Logger {
/**
* Name of this logger's "owner class" - the logging service client class that first requested this logger instance
* via the {@link Logger#instance()} service access method. The owner class is usually the same as the "caller
* class" - the client class that calls the service interface methods such as {@link Logger#log(Object)}.
* Name of this logger's declaring class - the logging service client class that first requested this logger
* instance via the {@link Logger#instance()} service access method. The declaring class is usually the same as the
* "caller class" - the client class that calls the service interface methods such as {@link Logger#log(Object)}.
* <p>
* In rare and not-recommended scenarios, the owner class can be different from the caller class: e.g. the owner
* class could pass a reference of this logger instance out to a different/caller class. Once set, though, the value
* of this field will never change even when the owner class is different from the caller class.
* In rare and not-recommended scenarios, the declaring class can be different from the caller class: e.g. the
* declaring class could pass a reference of this logger instance out to a different/caller class. Once set, though,
* the value of this field will never change even when the declaring class is different from the caller class.
* <p>
* To reduce the frequency of having to walk the call stack in order to locate the caller class, this native ELF4J
* implementation assumes the owner and caller class to be one and the same. Thus, for logging output that requires
* only the caller class name, this field will be used in liu of checking the stack trace; i.e. the stack trace
* walking is needed only when more caller details (e.g. method name, file name, line number) are required.
* implementation assumes the declaring and caller class to be one and the same. Thus, for logging output that
* requires only the caller class name, this field will be used in liu of checking the stack trace; i.e. the stack
* trace walking is needed only when more caller details (e.g. method name, file name, line number) are required.
*/
private final @NonNull String ownerClassName;
private final @NonNull String declaringClassName;

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

/**
* Constructor only meant to be used by {@link NativeLoggerFactory} and this class itself
*
* @param ownerClassName name of the owner class that requested this instance via the {@link Logger#instance()}
* method
* @param level severity level of this logger instance
* @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
*/
public NativeLogger(
@NonNull String ownerClassName, @NonNull Level level, @NonNull NativeLoggerFactory nativeLoggerFactory) {
this.ownerClassName = ownerClassName;
@NonNull String declaringClassName,
@NonNull Level level,
@NonNull NativeLoggerFactory nativeLoggerFactory) {
this.declaringClassName = declaringClassName;
this.level = level;
this.nativeLoggerFactory = nativeLoggerFactory;
}

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

@Override
Expand Down Expand Up @@ -121,10 +123,10 @@ public LogService getLogService() {
}

/**
* @return owner/caller class of this logger instance
* @return declaring/caller class of this logger instance
*/
public @NonNull String getOwnerClassName() {
return this.ownerClassName;
public @NonNull String getDeclaringClassName() {
return this.declaringClassName;
}

private void service(Throwable throwable, Object message, Object[] arguments) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/elf4j/engine/service/LogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class LogEvent {
* @return the name of the application client class calling the logging method of this logger instance
*/
public String getCallerClassName() {
return callerFrame != null ? callerFrame.getClassName() : nativeLogger.getOwnerClassName();
return callerFrame != null ? callerFrame.getClassName() : nativeLogger.getDeclaringClassName();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static Optional<Level> getAsLevel(String levelKey, @NonNull Properties p
*/
public Level getMinimumOutputLevel(@NonNull NativeLogger nativeLogger) {
return this.sortedCallerClassNameSpaces.stream()
.filter(classNameSpace -> nativeLogger.getOwnerClassName().startsWith(classNameSpace))
.filter(classNameSpace -> nativeLogger.getDeclaringClassName().startsWith(classNameSpace))
.findFirst()
.map(this.configuredLevels::get)
.orElse(nativeLogger.getLevel());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/elf4j/engine/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void hey() {
new Exception("Test ex message"),
this.getClass());

assertEquals(this.getClass().getName(), ((NativeLogger) logger).getOwnerClassName());
assertEquals(this.getClass().getName(), ((NativeLogger) logger).getDeclaringClassName());
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/elf4j/engine/NativeLoggerFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void level() {

@Test
void name() {
assertSame(this.getClass().getName(), sut.logger().getOwnerClassName());
assertSame(this.getClass().getName(), sut.logger().getDeclaringClassName());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/elf4j/engine/NativeLoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void instanceForDifferentLevel() {
NativeLogger warn = (NativeLogger) info.atWarn();

assertNotSame(warn, info);
assertEquals(info.getOwnerClassName(), warn.getOwnerClassName());
assertEquals(info.getDeclaringClassName(), warn.getDeclaringClassName());
assertEquals(WARN, warn.getLevel());
}

Expand Down

0 comments on commit d5d8d7e

Please sign in to comment.