Skip to content

Commit

Permalink
+ spotless palantir format version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Feb 18, 2024
1 parent 31c5503 commit b466a60
Show file tree
Hide file tree
Showing 35 changed files with 140 additions and 228 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.39.0</version>
<version>2.40.0</version> <!-- optional -->
<style>PALANTIR</style> <!-- or AOSP/GOOGLE (optional) -->
<formatJavadoc>true
</formatJavadoc> <!-- defaults to false (optional, requires at least Palantir 2.39.0) -->
</palantirJavaFormat>
<formatAnnotations/>
</java>
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/elf4j/engine/NativeLogServiceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,19 @@
import lombok.NonNull;
import org.slf4j.MdcAdapterInitializer;

/**
*
*/
/** */
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
*/
/** Made injectable for extensions other than this native ELF4J implementation */
@NonNull private final Level defaultLoggerLevel;

private final Map<Level, Map<String, NativeLogger>> nativeLoggers =
EnumSet.allOf(Level.class).stream().collect(toMap(Function.identity(), level -> new ConcurrentHashMap<>()));
/**
* The class or interface that the API client calls first to get a logger instance. The client caller class of this
* class will be the declaring class of the logger instances this factory produces.
* <p></p>
* For this native implementation, the service access class is the {@link Logger} interface itself as the client
*
* <p>For this native implementation, the service access class is the {@link Logger} interface itself as the client
* calls the static factory method {@link Logger#instance()} first to get a logger instance. If this library is used
* as the engine of another logging API, then this access class would be the class in that API that the client calls
* first to get a logger instance of that API.
Expand All @@ -69,16 +65,13 @@ public class NativeLogServiceProvider implements LogServiceProvider, NativeLogSe

@NonNull private final NativeLogServiceProvider.NativeLoggerServiceFactory nativeLoggerServiceFactory;

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

/**
* @param serviceAccessClass the class or interface that the API client application calls first to a logger
* instance
* @param serviceAccessClass the class or interface that the API client application calls first to a logger instance
*/
public NativeLogServiceProvider(@NonNull Class<?> serviceAccessClass) {
this(DEFAULT_LOGGER_SEVERITY_LEVEL, serviceAccessClass, new ConfiguredNativeLoggerServiceFactory());
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/elf4j/engine/NativeLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class NativeLogger implements Logger {
* 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 declaring class can be different from the caller class: e.g. the
*
* <p>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 declaring and caller class to be one and the same. Thus, for logging output that
*
* <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 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.
*/
Expand All @@ -62,7 +62,7 @@ public class NativeLogger implements Logger {
* 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
* {@link Logger#instance()} method
* @param level severity level of this logger instance
* @param nativeLogServiceProvider log service access point from this instance, not reloadable
*/
Expand Down Expand Up @@ -115,16 +115,12 @@ public void log(Throwable throwable, String message, Object... arguments) {
this.service(throwable, message, arguments);
}

/**
* @return directly callable log service, useful for other logging frameworks to use this engine
*/
/** @return directly callable log service, useful for other logging frameworks to use this engine */
public NativeLoggerService getLogService() {
return this.nativeLogServiceProvider.getLogService();
}

/**
* @return declaring/caller class of this logger instance
*/
/** @return declaring/caller class of this logger instance */
public @NonNull String getDeclaringClassName() {
return this.declaringClassName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import java.util.concurrent.ConcurrentHashMap;
import lombok.NonNull;

/**
* converts a log request into an event for async processing
*/
/** converts a log request into an event for async processing */
public class EventingNativeLoggerService implements NativeLoggerService {
private final boolean noop;
private final LogWriter logWriter;
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/elf4j/engine/service/LogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import lombok.NonNull;
import lombok.Value;

/**
* Source data to be rendered to a final log message
*/
/** Source data to be rendered to a final log message */
@Value
@Builder
public class LogEvent {
Expand Down Expand Up @@ -86,23 +84,17 @@ public class LogEvent {
return o instanceof Supplier<?> ? ((Supplier<?>) o).get() : o;
}

/**
* @return the name of the application client class calling the logging method of this logger instance
*/
/** @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.getDeclaringClassName();
}

/**
* @return log message text with all placeholder arguments resolved and replaced by final values
*/
/** @return log message text with all placeholder arguments resolved and replaced by final values */
public CharSequence getResolvedMessage() {
return resolve(this.message, this.arguments);
}

/**
*
*/
/** */
@Value
@Builder
public static class StackFrameValue {
Expand All @@ -124,9 +116,7 @@ public static StackFrameValue from(StackTraceElement stackTraceElement) {
}
}

/**
*
*/
/** */
@Value
public static class ThreadValue {
@NonNull String name;
Expand Down
48 changes: 14 additions & 34 deletions src/main/java/elf4j/engine/service/NativeLogServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
import lombok.NonNull;
import lombok.ToString;

/**
*
*/
/** */
@ToString
public enum NativeLogServiceManager {
/**
*
*/
/** */
INSTANCE;

private final Set<Refreshable> refreshables = new HashSet<>();
Expand All @@ -51,25 +47,19 @@ public enum NativeLogServiceManager {
@ToString.Exclude
private final Lock lock = new ReentrantLock();

/**
* @param refreshable added to be accessible for management
*/
/** @param refreshable added to be accessible for management */
public void register(Refreshable refreshable) {
lockAndRun(() -> refreshables.add(refreshable));
IeLogger.INFO.log("Registered Refreshable {} in {}", refreshable, this);
}

/**
* @param stoppable added to be accessible for management
*/
/** @param stoppable added to be accessible for management */
public void register(Stoppable stoppable) {
lockAndRun(() -> stoppables.add(stoppable));
IeLogger.INFO.log("Registered Stoppable {} in {}", stoppable, this);
}

/**
* reloads properties source for each refreshable
*/
/** reloads properties source for each refreshable */
public void refresh() {
IeLogger.INFO.log("Refreshing elf4j service by {} via reloading properties", this);
lockAndRun(() -> {
Expand All @@ -81,7 +71,7 @@ public void refresh() {

/**
* @param properties if non-null, replaces current configuration with the specified properties, instead of reloading
* from the original properties source; otherwise, reloads the original properties source for each refreshable.
* from the original properties source; otherwise, reloads the original properties source for each refreshable.
*/
public void refresh(Properties properties) {
IeLogger.INFO.log("Refreshing elf4j service by {} with properties {}", this, properties);
Expand All @@ -92,9 +82,7 @@ public void refresh(Properties properties) {
IeLogger.INFO.log("Refreshed elf4j service by {} with properties {}", this, properties);
}

/**
*
*/
/** */
public void shutdown() {
IeLogger.INFO.log("Start shutting down elf4j service by {}", this);
lockAndRun(() -> {
Expand All @@ -106,7 +94,7 @@ public void shutdown() {

/**
* @return a thread that orderly stops the entire log service. As an alternative to calling {@link #shutdown()}, the
* returned thread can be registered as a JVM shutdown hook.
* returned thread can be registered as a JVM shutdown hook.
*/
@NonNull public Thread getShutdownHookThread() {
return new Thread(this::shutdown);
Expand All @@ -126,30 +114,22 @@ private void lockAndRun(@NonNull Runnable runnable) {
}
}

/**
*
*/
/** */
public interface Refreshable {
/**
* @param properties used to refresh the logging configuration. If <code>null</code>, only properties reloaded
* from the configuration file will be used. Otherwise, the specified properties will replace all current
* properties and configuration file is ignored.
* from the configuration file will be used. Otherwise, the specified properties will replace all current
* properties and configuration file is ignored.
*/
void refresh(@Nullable Properties properties);

/**
* reloads from original source of properties
*/
/** reloads from original source of properties */
void refresh();
}

/**
*
*/
/** */
public interface Stoppable {
/**
*
*/
/** */
void stop();
}
}
13 changes: 6 additions & 7 deletions src/main/java/elf4j/engine/service/NativeLoggerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@

import elf4j.engine.NativeLogger;

/**
*
*/
/** */
public interface NativeLoggerService extends PerformanceSensitive {
/**
* @param nativeLogger to check for enablement
Expand All @@ -40,10 +38,11 @@ public interface NativeLoggerService extends PerformanceSensitive {
/**
* @param nativeLogger the serviced logger
* @param serviceInterfaceClass The concrete logging service (logger) implementation class that the client calls
* directly at runtime to make log requests. For the native ELF4J service implementation, this is always the
* {@link NativeLogger} class; may be a different class if this core library is used to service other logging API.
* i.e. the real-time caller of this class is the logging service's "caller class" whose details (such as method and
* line number) if required by configuration, may need to be resolved by walking the runtime calling stack trace.
* directly at runtime to make log requests. For the native ELF4J service implementation, this is always the
* {@link NativeLogger} class; may be a different class if this core library is used to service other logging
* API. i.e. the real-time caller of this class is the logging service's "caller class" whose details (such as
* method and line number) if required by configuration, may need to be resolved by walking the runtime calling
* stack trace.
* @param throwable to log
* @param message to log, can have argument placeholders to be replaced by the values of the specified arguments
* @param arguments arguments whose values will replace the placeholders in the specified message
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/elf4j/engine/service/PerformanceSensitive.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@

package elf4j.engine.service;

/**
*
*/
/** */
public interface PerformanceSensitive {
/**
* @return true if log should include caller detail such as method, line number...
*/
/** @return true if log should include caller detail such as method, line number... */
boolean includeCallerDetail();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;

/**
* The type Log service configuration.
*/
/** The type Log service configuration. */
@ToString(doNotUseGetters = true)
@EqualsAndHashCode
public class LogServiceConfiguration {
Expand Down Expand Up @@ -84,7 +87,7 @@ public boolean isAbsent() {
*
* @param name full key in properties
* @return Integer value of the specified name in the given properties, null if named entry missing or the
* corresponding value contains no digit
* corresponding value contains no digit
*/
@Nullable public Integer getAsInteger(String name) {
String value = getProperties().getProperty(name);
Expand Down Expand Up @@ -119,7 +122,7 @@ public int getIntOrDefault(String name, int defaultValue) {
*
* @param prefix key prefix to search for
* @return all properties entries whose original keys start with the specified prefix. The prefix is removed from
* the keys of the returned map.
* the keys of the returned map.
* @see #getPropertiesGroupOfType(String)
*/
public Map<String, String> getChildProperties(String prefix) {
Expand All @@ -139,7 +142,7 @@ public Map<String, String> getChildProperties(String prefix) {
*
* @param type the value whose keys are each used as a parent key prefix of a child properties map
* @return a child properties map group whose every member is a properties map having a common parent key prefix of
* the specified type
* the specified type
* @see #getChildProperties(String)
*/
public List<Map<String, String>> getPropertiesGroupOfType(String type) {
Expand Down Expand Up @@ -173,21 +176,15 @@ public boolean isTrue(String name) {
return Boolean.parseBoolean(getProperties().getProperty(name));
}

/**
* The type Properties file loader.
*/
/** The type Properties file loader. */
static class PropertiesFileLoader {
/**
*
*/
/** */
static final String ELF4J_PROPERTIES_LOCATION = "elf4j.properties.location";

private static final String[] DEFAULT_PROPERTIES_LOCATIONS =
new String[] {"/elf4j-test.properties", "/elf4j.properties"};

/**
* @return configuration properties loaded from either the default or specified location
*/
/** @return configuration properties loaded from either the default or specified location */
@Nullable public Properties load() {
Properties properties = new Properties();
InputStream propertiesInputStream;
Expand Down
Loading

0 comments on commit b466a60

Please sign in to comment.