org.zodiac.reactor.logger.ReactiveLogger Maven / Gradle / Ivy
The newest version!
package org.zodiac.reactor.logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Signal;
import reactor.core.publisher.SignalType;
import reactor.core.publisher.SynchronousSink;
import reactor.util.context.Context;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
public abstract class ReactiveLogger {
private ReactiveLogger() {
super();
}
private static Logger log = LoggerFactory.getLogger(ReactiveLogger.class);
private static final String CONTEXT_KEY = ReactiveLogger.class.getName();
public static Function start(String key, String value) {
return start(Collections.singletonMap(key, value));
}
public static Function start(String... keyAndValue) {
Map map = new HashMap<>();
for (int i = 0, len = keyAndValue.length / 2; i < len; i++) {
map.put(keyAndValue[i * 2], keyAndValue[i * 2 + 1]);
}
return start(map);
}
public static Mono mdc(String key, String value) {
return Mono
.empty()
.subscriberContext(start(key, value));
}
public static Mono mdc(String... keyAndValue) {
return Mono
.empty()
.subscriberContext(start(keyAndValue));
}
public static Function start(Map context) {
return ctx -> {
Optional
© 2015 - 2024 Weber Informatics LLC | Privacy Policy