Update log4j2.xml, LogServiceImpl.java, and 4 more files...

This commit is contained in:
Andrea Cavalli 2020-10-19 16:00:16 +02:00
parent b9fbc22c11
commit 351979fe0b
6 changed files with 65 additions and 15 deletions

38
log4j2.xml Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- log4j2.xml - Example log4j configuration file
Place this file in the same directory as your server.jar, edit
to taste, and add -Dlog4j.configurationFile=log4j2.xml to your
server startup flags.
More log4j example configs can be found at
<http://logging.apache.org/log4j/2.x/manual/appenders.html>.
-->
<Configuration status="trace" shutdownHook="disable">
<Appenders>
<!-- DEFAULT APPENDERS -->
<!-- console logging - logs to stdout -->
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
<PatternLayout disableAnsi="false" pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{%processId}{magenta} [%15.15t] %style{%-20.20c{1}}{cyan} : %m%n%ex"/>
</Console>
<!-- console logging - logs to stderr -->
<Console name="ConsoleAppenderErr" target="SYSTEM_ERR" follow="true">
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout disableAnsi="false" pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{%processId}{magenta} [%15.15t] %style{%-20.20c{1}}{cyan} : %m%n%ex"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.hazelcast" level="INFO" />
<Root level="DEBUG">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY"
onMismatch="NEUTRAL" />
</filters>
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="ConsoleAppenderErr"/>
</Root>
</Loggers>
</Configuration>

View File

@ -21,7 +21,7 @@ public class LogServiceImpl implements LogService {
@Override @Override
public void append(Level level, String message) { public void append(Level level, String message) {
logs.onNext(new LogEntry(System.currentTimeMillis(), level, message)); logs.onNext(new LogEntry(System.currentTimeMillis(), level, message.length() > 512 ? message.substring(0, 512) : message));
} }
@Override @Override

View File

@ -35,7 +35,7 @@ public class TransferClient {
this.client = client; this.client = client;
this.client.getIncomingUpdates() this.client.getIncomingUpdates()
.subscribeOn(Schedulers.boundedElastic()) .subscribeOn(Schedulers.newParallel("bot_updates"))
.flatMap(this::onUpdate) .flatMap(this::onUpdate)
.subscribe(); .subscribe();
} }

View File

@ -128,7 +128,7 @@ public class TransferServiceImpl implements TransferService {
}) })
.build()) .build())
.then(Mono.defer(() -> { .then(Mono.defer(() -> {
var clientStateFlux = client.getState().publish().autoConnect(2); var clientStateFlux = client.getState().skip(1).publish().autoConnect(2);
clientStateFlux clientStateFlux
.filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR .filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR
@ -140,12 +140,14 @@ public class TransferServiceImpl implements TransferService {
.materialize() .materialize()
.flatMap(signal -> onUserbotClosed.get().thenReturn(signal)) .flatMap(signal -> onUserbotClosed.get().thenReturn(signal))
.dematerialize() .dematerialize()
.subscribe(state -> System.out.println("State: " + state)); .subscribe(state -> System.out.println("Userbot closed with state: " + state));
clientStateFlux.subscribe(state -> System.out.println("state: " + state));
client client
.getIncomingUpdates() .getIncomingUpdates()
.flatMap(this::onClientUpdate) .flatMap(update -> onClientUpdate(update))
.subscribe(u -> System.out.println(u), e -> System.err.println(e)); .subscribe(_v -> {}, e -> System.err.println(e));
return clientStateFlux return clientStateFlux
.filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR .filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR

View File

@ -15,14 +15,13 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers; import reactor.core.scheduler.Schedulers;
public class TransferUtils { public class TransferUtils {
private static final Logger logger = LoggerFactory.getLogger(TransferUtils.class);
public static int chatIdToChatEntityId(long id) { public static int chatIdToChatEntityId(long id) {
if (id <= -1000000000000L) { if (id <= -1000000000000L) {
return (int) (Math.abs(id) - 1000000000000L); return (int) (Math.abs(id) - 1000000000000L);
@ -49,6 +48,7 @@ public class TransferUtils {
private static class ChatIdAndOrderOffsets { private static class ChatIdAndOrderOffsets {
private final long chatIdOffset; private final long chatIdOffset;
private final long orderOffset; private final long orderOffset;
@ -98,7 +98,7 @@ public class TransferUtils {
* @return flux of home chats. They can repeat themselves * @return flux of home chats. They can repeat themselves
*/ */
public static Flux<Chat> getAllHomeChats(TransferClient client) { public static Flux<Chat> getAllHomeChats(TransferClient client) {
logger.debug("Getting the full chat list"); App.getLogService().append(Level.DEBUG, "Getting the full chat list");
var singleScheduler = Schedulers.newSingle("getallchats"); var singleScheduler = Schedulers.newSingle("getallchats");
@ -106,20 +106,27 @@ public class TransferUtils {
.deferWithContext((context) -> { .deferWithContext((context) -> {
var offsets = Objects.requireNonNull(context.<AtomicReference<ChatIdAndOrderOffsets>>get("offsets")); var offsets = Objects.requireNonNull(context.<AtomicReference<ChatIdAndOrderOffsets>>get("offsets"));
var offsetsValue = offsets.get(); var offsetsValue = offsets.get();
return client.<Chats>send(new GetChats(new ChatListMain(), App.getLogService().append(Level.TRACE, "Requesting GetChats");
offsetsValue.getOrderOffset(), return client.<Chats>send(new GetChats(new ChatListMain(),
offsetsValue.getChatIdOffset(), offsetsValue.getOrderOffset(),
100)) offsetsValue.getChatIdOffset(),
100
))
.flatMap(MonoUtils::orElseThrow) .flatMap(MonoUtils::orElseThrow)
.publishOn(singleScheduler) .publishOn(singleScheduler)
.flatMapMany(chats -> Flux.fromStream(Arrays.stream(chats.chatIds).boxed())) .flatMapMany(chats -> Flux.fromStream(Arrays.stream(chats.chatIds).boxed()))
.flatMap(chatId -> { .flatMap(chatId -> {
App.getLogService().append(Level.TRACE, "Received ChatId: " + chatId);
return client.<Chat>send(new GetChat(chatId)) return client.<Chat>send(new GetChat(chatId))
.publishOn(singleScheduler) .publishOn(singleScheduler)
.flatMap(MonoUtils::orElseThrow); .flatMap(MonoUtils::orElseThrow);
}) })
.doOnNext(chat -> {
App.getLogService().append(Level.TRACE, "Received Chat: " + chat.toString().replace('\n', ' ').replace(" ", "").replace("\t", ""));
})
.collectList() .collectList()
.doOnNext(chats -> { .doOnNext(chats -> {
App.getLogService().append(Level.TRACE, "Received Chats: " + chats.toString().replace('\n', ' ').replace(" ", "").replace("\t", ""));
if (!chats.isEmpty()) { if (!chats.isEmpty()) {
var lastChat = chats.get(chats.size() - 1); var lastChat = chats.get(chats.size() - 1);
getMainChatListPosition(lastChat.positions).ifPresentOrElse(lastChatPosition -> { getMainChatListPosition(lastChat.positions).ifPresentOrElse(lastChatPosition -> {
@ -136,7 +143,10 @@ public class TransferUtils {
}) })
.repeatWhen(nFlux -> nFlux.takeWhile(n -> n > 0)) .repeatWhen(nFlux -> nFlux.takeWhile(n -> n > 0))
.flatMap(Flux::fromIterable) .flatMap(Flux::fromIterable)
.subscriberContext(ctx -> ctx.put("offsets", new AtomicReference<>(new ChatIdAndOrderOffsets(0L, 9223372036854775807L)))); .subscriberContext(ctx -> ctx.put("offsets",
new AtomicReference<>(new ChatIdAndOrderOffsets(0L, 9223372036854775807L))
))
.doOnTerminate(() -> App.getLogService().append(Level.DEBUG, "Home chats retrieved"));
} }
private static Optional<ChatPosition> getMainChatListPosition(ChatPosition[] positions) { private static Optional<ChatPosition> getMainChatListPosition(ChatPosition[] positions) {

@ -1 +1 @@
Subproject commit bc40e2b9e60857e3b84850d11ba399a2afc51073 Subproject commit a7223c4d834c91829b2eace051c0ab5526720aed