Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package org.apache.bookkeeper.common.allocator;

import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;

/**
* Define the policy for the Netty leak detector.
*/
@Slf4j
@CustomLog
public enum LeakDetectionPolicy {

/**
Expand Down Expand Up @@ -55,8 +55,10 @@ public static LeakDetectionPolicy parseLevel(String levelStr) {
return policy;
}
}
log.warn("Parse leak detection policy level {} failed. Use the default level: {}", levelStr,
LeakDetectionPolicy.Disabled.name());
log.warn()
.attr("levelStr", levelStr)
.attr("defaultLevel", LeakDetectionPolicy.Disabled.name())
.log("Parse leak detection policy level failed. Using the default level");
return LeakDetectionPolicy.Disabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;

/**
* Forked from <a href="https://github.com/apache/pulsar">Pulsar</a>.
*/
@Slf4j
@CustomLog
public class ShutdownUtil {
private static final Method log4j2ShutdownMethod;

Expand All @@ -37,7 +37,7 @@ public class ShutdownUtil {
.getMethod("shutdown");
} catch (ClassNotFoundException | NoSuchMethodException e) {
// ignore when Log4j2 isn't found, log at debug level
log.debug("Cannot find org.apache.logging.log4j.LogManager.shutdown method", e);
log.debug().exception(e).log("Cannot find org.apache.logging.log4j.LogManager.shutdown method");
}
log4j2ShutdownMethod = shutdownMethod;
}
Expand All @@ -54,8 +54,10 @@ public static void triggerImmediateForcefulShutdown(int status) {
public static void triggerImmediateForcefulShutdown(int status, boolean logging) {
try {
if (status != 0 && logging) {
log.warn("Triggering immediate shutdown of current process with status {}", status,
new Exception("Stacktrace for immediate shutdown"));
log.warn()
.exception(new Exception("Stacktrace for immediate shutdown"))
.attr("status", status)
.log("Triggering immediate shutdown of current process");
}
shutdownLogging();
} finally {
Expand All @@ -70,7 +72,9 @@ private static void shutdownLogging() {
// use reflection to call org.apache.logging.log4j.LogManager.shutdown()
log4j2ShutdownMethod.invoke(null);
} catch (IllegalAccessException | InvocationTargetException e) {
log.error("Unable to call org.apache.logging.log4j.LogManager.shutdown using reflection.", e);
log.error()
.exception(e)
.log("Unable to call org.apache.logging.log4j.LogManager.shutdown using reflection");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import lombok.CustomLog;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

/**
* Utility class to use "Thread.onSpinWait()" when available.
*/
@UtilityClass
@Slf4j
@CustomLog
public class BusyWait {

/**
Expand All @@ -54,9 +54,7 @@ public static void onSpinWait() {
handle = MethodHandles.lookup().findStatic(Thread.class, "onSpinWait", MethodType.methodType(void.class));
} catch (Throwable t) {
// Ignore
if (log.isDebugEnabled()) {
log.debug("Unable to use 'onSpinWait' from JVM", t);
}
log.debug().exception(t).log("Unable to use 'onSpinWait' from JVM");
}

ON_SPIN_WAIT = handle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;

/**
* Allows a component to publish information about
* the services it implements, the endpoints it exposes
* and other useful information for management tools and client.
*/
@Slf4j
@CustomLog
public class ComponentInfoPublisher {

private final Map<String, String> properties = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -99,9 +99,10 @@ public String toString() {
* @param value the value, null values are not allowed.
*/
public void publishProperty(String key, String value) {
if (log.isDebugEnabled()) {
log.debug("publish {}={}", key, value);
}
log.debug()
.attr("key", key)
.attr("value", value)
.log("publish");
if (startupFinished) {
throw new IllegalStateException("Server already started, cannot publish " + key);
}
Expand All @@ -112,9 +113,10 @@ public void publishProperty(String key, String value) {
}

public void publishEndpoint(EndpointInfo endpoint) {
if (log.isDebugEnabled()) {
log.debug("publishEndpoint {} on {}", endpoint, this);
}
log.debug()
.attr("endpoint", endpoint)
.attr("publisher", this)
.log("publishEndpoint");
EndpointInfo exists = endpoints.put(endpoint.id, endpoint);
if (exists != null) {
throw new IllegalStateException("An endpoint with id " + endpoint.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
package org.apache.bookkeeper.common.component;

import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;
import org.apache.bookkeeper.common.concurrent.FutureUtils;

/**
* Utils to start components.
*/
@Slf4j
@CustomLog
public class ComponentStarter {

static class ComponentShutdownHook implements Runnable {
Expand All @@ -41,14 +41,18 @@ static class ComponentShutdownHook implements Runnable {

@Override
public void run() {
log.info("Closing component {} in shutdown hook.", component.getName());
log.info().attr("component", component.getName()).log("Closing component in shutdown hook");
try {
component.close();
log.info("Closed component {} in shutdown hook successfully. Exiting.", component.getName());
log.info()
.attr("component", component.getName())
.log("Closed component in shutdown hook successfully. Exiting");
FutureUtils.complete(future, null);
} catch (Throwable e) {
log.error("Failed to close component {} in shutdown hook gracefully, Exiting anyway",
component.getName(), e);
log.error()
.exception(e)
.attr("component", component.getName())
.log("Failed to close component in shutdown hook gracefully, Exiting anyway");
future.completeExceptionally(e);
}
}
Expand All @@ -72,8 +76,11 @@ public static CompletableFuture<Void> startComponent(LifecycleComponent componen

// register a component exception handler
component.setExceptionHandler((t, e) -> {
log.error("Triggered exceptionHandler of Component: {} because of Exception in Thread: {}",
component.getName(), t, e);
log.error()
.exception(e)
.attr("component", component.getName())
.attr("thread", t)
.log("Triggered exceptionHandler of Component because of Exception in Thread");
System.err.println(e.getMessage());
// start the shutdown hook when an uncaught exception happen in the lifecycle component.
try {
Expand All @@ -86,9 +93,9 @@ public static CompletableFuture<Void> startComponent(LifecycleComponent componen

component.publishInfo(new ComponentInfoPublisher());

log.info("Starting component {}.", component.getName());
log.info().attr("component", component.getName()).log("Starting component");
component.start();
log.info("Started component {}.", component.getName());
log.info().attr("component", component.getName()).log("Started component");
return future;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import com.google.common.collect.Lists;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;

/**
* A stack of {@link LifecycleComponent}s.
*/
@Slf4j
@CustomLog
public class LifecycleComponentStack implements LifecycleComponent {

public static Builder newBuilder() {
Expand Down Expand Up @@ -124,19 +124,15 @@ public void removeLifecycleListener(LifecycleListener listener) {
@Override
public void publishInfo(ComponentInfoPublisher componentInfoPublisher) {
components.forEach(component -> {
if (log.isDebugEnabled()) {
log.debug("calling publishInfo on {} ", component);
}
log.debug().attr("component", component).log("calling publishInfo");
component.publishInfo(componentInfoPublisher);
});
}

@Override
public void start() {
components.forEach(component -> {
if (log.isDebugEnabled()) {
log.debug("calling publishInfo on {} ", component);
}
log.debug().attr("component", component).log("calling publishInfo");
component.publishInfo(componentInfoPublisher);
});
componentInfoPublisher.startupFinished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.CustomLog;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.stats.OpStatsListener;
import org.apache.bookkeeper.common.util.OrderedScheduler;
import org.apache.bookkeeper.stats.OpStatsLogger;

/**
* Future related utils.
*/
@Slf4j
@CustomLog
public final class FutureUtils {

private FutureUtils() {}
Expand Down Expand Up @@ -234,9 +234,7 @@ public void onFailure(final Throwable cause) {
@Override
public void run() {
if (done) {
if (log.isDebugEnabled()) {
log.debug("ListFutureProcessor is interrupted.");
}
log.debug("ListFutureProcessor is interrupted");
return;
}
if (!itemsIter.hasNext()) {
Expand Down Expand Up @@ -294,12 +292,12 @@ public static <T> CompletableFuture<T> within(final CompletableFuture<T> promise
// schedule a timeout to raise timeout exception
final java.util.concurrent.ScheduledFuture<?> task = scheduler.scheduleOrdered(key, () -> {
if (!promise.isDone() && promise.completeExceptionally(cause)) {
log.info("Raise exception", cause);
log.info().exception(cause).log("Raise exception");
}
}, timeout, unit);
// when the promise is satisfied, cancel the timeout task
promise.whenComplete((value, throwable) -> {
if (!task.cancel(true) && log.isDebugEnabled()) {
if (!task.cancel(true)) {
log.debug("Failed to cancel the timeout task");
}
}
Expand Down Expand Up @@ -336,7 +334,7 @@ public void onSuccess(T value) {
@Override
public void onFailure(Throwable cause) {
if (null != errorMsg) {
log.error(errorMsg, cause);
log.error().exception(cause).log(errorMsg);
}
promise.complete(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import lombok.CustomLog;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.lang3.StringUtils;

/**
* A definition of a configuration instance.
*/
@Slf4j
@CustomLog
@Getter
public class ConfigDef {

Expand Down Expand Up @@ -160,7 +160,11 @@ public static ConfigDef of(Class configClass) {
try {
builder.withConfigKey((ConfigKey) field.get(null));
} catch (IllegalAccessException e) {
log.error("Illegal to access {}#{}", configClass.getSimpleName(), field.getName(), e);
log.error()
.exception(e)
.attr("configClass", configClass.getSimpleName())
.attr("field", field.getName())
.log("Illegal to access field");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import lombok.Builder.Default;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.annotation.InterfaceAudience.Public;
import org.apache.bookkeeper.common.conf.validators.NullValidator;
import org.apache.bookkeeper.common.util.ReflectionUtils;
Expand All @@ -43,7 +42,6 @@
@Builder(builderMethodName = "internalBuilder")
@Accessors(fluent = true)
@Public
@Slf4j
public class ConfigKey {

public static final Comparator<ConfigKey> ORDERING = (o1, o2) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package org.apache.bookkeeper.common.conf.validators;

import lombok.CustomLog;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.conf.Validator;
import org.apache.bookkeeper.common.util.ReflectionUtils;

/**
* Validator that validates a configuration setting is returning a given type of class.
*/
@Slf4j
@CustomLog
@Data
public class ClassValidator<T> implements Validator {

Expand All @@ -51,15 +51,22 @@ public boolean validate(String name, Object value) {
ReflectionUtils.forName((String) value, interfaceClass);
return true;
} catch (RuntimeException re) {
log.warn("Setting value of '{}' is not '{}' : {}",
name, interfaceClass.getName(), value, re);
log.warn()
.exception(re)
.attr("name", name)
.attr("interfaceClass", interfaceClass.getName())
.attr("value", value)
.log("Setting value does not match expected interface");
return false;
}
} else if (value instanceof Class) {
Class cls = (Class) value;
if (!interfaceClass.isAssignableFrom(cls)) {
log.warn("Setting value of '{}' is not '{}' : {}",
name, interfaceClass.getName(), cls.getName());
log.warn()
.attr("name", name)
.attr("interfaceClass", interfaceClass.getName())
.attr("value", cls.getName())
.log("Setting value does not match expected interface");
return false;
} else {
return true;
Expand Down
Loading
Loading