Skip to content

Commit

Permalink
fix: fix cdi-log npe during the start of the application (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Oct 26, 2022
1 parent f3e675c commit 745f4cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.tkit.quarkus.log.cdi;

import java.util.List;
import java.util.stream.Collectors;

import javax.enterprise.inject.Any;

Expand All @@ -22,14 +21,14 @@ public class LogRecorder {

private static final Logger log = LoggerFactory.getLogger(LogRecorder.class);

static LogRuntimeConfig CONFIG;
static LogRuntimeConfig CONFIG = new LogRuntimeConfig();

static ServiceValue SERVICE;
static ServiceValue SERVICE = new ServiceValue();

public void init(ServiceValue values, LogRuntimeConfig config) {

InjectableInstance<LogParam> it = Arc.container().select(LogParam.class, Any.Literal.INSTANCE);
LogParamValueService.init(it.stream().collect(Collectors.toList()));
LogParamValueService.init(it.stream());

CONFIG = config;
SERVICE = values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Stream;

import org.tkit.quarkus.log.cdi.LogParam;

Expand All @@ -22,18 +23,18 @@ public class LogParamValueService {
public static Map<Class<?>, Function<Object, String>> ASSIGNABLE_FROM = new HashMap<>(
JavaTypesLogParamValue.assignableFrom());

public static void init(List<LogParam> services) {
if (services != null && !services.isEmpty()) {
public static void init(Stream<LogParam> services) {
if (services != null) {
Map<Class<?>, LogParam.Item> classes = new HashMap<>();
Map<Class<?>, LogParam.Item> assignable = new HashMap<>();
for (LogParam def : services) {
services.forEach(def -> {
if (def.getClasses() != null) {
map(def.getClasses(), classes);
}
if (def.getAssignableFrom() != null) {
map(def.getAssignableFrom(), assignable);
}
}
});
classes.forEach((c, item) -> CLASSES.put(c, item.fn));
assignable.forEach((c, item) -> ASSIGNABLE_FROM.put(c, item.fn));
}
Expand Down

0 comments on commit 745f4cc

Please sign in to comment.