From 461c99902924a5cf9fb552c57af2bca6c6761fc7 Mon Sep 17 00:00:00 2001 From: Yordan Atanasov Date: Mon, 30 Sep 2024 11:31:31 +0300 Subject: [PATCH] chore: Remove DivLogger, usages and teavm debug. --- build.gradle.kts | 8 ------- src/main/java/com/limechain/Main.java | 11 ++++------ .../com/limechain/client/LightClient.java | 9 +++----- .../com/limechain/config/ChainService.java | 11 ++++------ .../java/com/limechain/config/SystemInfo.java | 21 ++++++++----------- .../sync/warpsync/WarpSyncMachine.java | 8 +++---- .../java/com/limechain/utils/DivLogger.java | 18 ---------------- 7 files changed, 23 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/com/limechain/utils/DivLogger.java diff --git a/build.gradle.kts b/build.gradle.kts index d528be5dd..7931cbd49 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,12 +31,4 @@ teavm.js { mainClass = "com.limechain.Main" targetFileName = "fruzhin.js" moduleType = JSModuleType.ES2015 -} - -//TODO: Debug only. Remove when doing release build -teavm { - js { - sourceMap.set(true) - debugInformation.set(true) - } } \ No newline at end of file diff --git a/src/main/java/com/limechain/Main.java b/src/main/java/com/limechain/Main.java index 1666bb377..cb2712c67 100644 --- a/src/main/java/com/limechain/Main.java +++ b/src/main/java/com/limechain/Main.java @@ -7,25 +7,22 @@ import com.limechain.config.CommonConfig; import com.limechain.rpc.WsRpcClient; import com.limechain.rpc.WsRpcClientImpl; -import com.limechain.utils.DivLogger; +import lombok.extern.java.Log; import org.teavm.jso.JSBody; import org.teavm.jso.core.JSString; -import java.util.logging.Level; - +@Log public class Main { private static final String WS_RPC = "wsRpc"; - private static final DivLogger log = new DivLogger(); - public static void main(String[] args) { if (args.length != 1) { throw new IllegalStateException( "Please provide a valid chain spec string or one of the supported chain names."); } - log.log("Starting LimeChain node..."); + log.info("Starting LimeChain node..."); String chainString = args[0]; initContext(chainString); @@ -33,7 +30,7 @@ public static void main(String[] args) { HostNode client = new LightClient(); client.start(); - log.log(Level.INFO, "\uD83D\uDE80Started light client!"); + log.info("\uD83D\uDE80Started light client!"); } private static void initContext(String chainString) { diff --git a/src/main/java/com/limechain/client/LightClient.java b/src/main/java/com/limechain/client/LightClient.java index f4d48367f..e5efc6826 100644 --- a/src/main/java/com/limechain/client/LightClient.java +++ b/src/main/java/com/limechain/client/LightClient.java @@ -3,22 +3,19 @@ import com.limechain.config.AppBean; import com.limechain.network.Network; import com.limechain.sync.warpsync.WarpSyncMachine; -import com.limechain.utils.DivLogger; import lombok.SneakyThrows; - -import java.util.logging.Level; +import lombok.extern.java.Log; /** * Main light client class that starts and stops execution of * the client and hold references to dependencies */ +@Log public class LightClient implements HostNode { // TODO: Add service dependencies i.e rpc, sync, network, etc. // TODO: Do we need those as fields here...? private final Network network; - private static final DivLogger log = new DivLogger(); - /** * @implNote the RpcApp is assumed to have been started before constructing the client, * as it relies on the application context @@ -35,7 +32,7 @@ public void start() { this.network.start(); WarpSyncMachine warpSyncMachine = AppBean.getBean(WarpSyncMachine.class); - log.log(Level.INFO, "Syncing to latest finalized block state..."); + log.fine("Syncing to latest finalized block state..."); int retryCount = 0; while (retryCount < 3) { diff --git a/src/main/java/com/limechain/config/ChainService.java b/src/main/java/com/limechain/config/ChainService.java index 351f2118d..acb1b18e4 100644 --- a/src/main/java/com/limechain/config/ChainService.java +++ b/src/main/java/com/limechain/config/ChainService.java @@ -3,11 +3,9 @@ import com.limechain.chain.Chain; import com.limechain.chain.spec.ChainSpec; import com.limechain.polkaj.Hash256; -import com.limechain.utils.DivLogger; import com.limechain.utils.json.ObjectMapper; import lombok.Getter; - -import java.util.logging.Level; +import lombok.extern.java.Log; // TODO: Cleanup @@ -15,6 +13,7 @@ * Configuration class used to store any Host specific information */ @Getter +@Log public class ChainService { private static final String GENESIS_DIR_FORMAT = "genesis/%s.json"; @@ -30,10 +29,8 @@ public class ChainService { */ private ChainSpec chainSpec; - private static final DivLogger log = new DivLogger(); - public void init(String chainString) { - log.log(Level.INFO, "Loading chain context..."); + log.fine("Loading chain context..."); Chain cliChain = Chain.fromString(chainString); try { @@ -48,7 +45,7 @@ public void init(String chainString) { System.out.println("Something went wrong while loading chain data. " + e.getMessage()); } - log.log(Level.INFO, "✅️Loaded chain context for the " + chain.getValue() + " chain."); + log.info("✅️Loaded chain context for the " + chain.getValue() + " chain."); } /** diff --git a/src/main/java/com/limechain/config/SystemInfo.java b/src/main/java/com/limechain/config/SystemInfo.java index dde125b7e..cb939e88e 100644 --- a/src/main/java/com/limechain/config/SystemInfo.java +++ b/src/main/java/com/limechain/config/SystemInfo.java @@ -1,9 +1,7 @@ package com.limechain.config; -import com.limechain.utils.DivLogger; import lombok.Getter; - -import java.util.logging.Level; +import lombok.extern.java.Log; //TODO: Cleanup @@ -11,6 +9,7 @@ * Configuration class used to hold and information used by the system rpc methods */ @Getter +@Log public class SystemInfo { // private final String role; private final ChainService chainService; @@ -18,8 +17,6 @@ public class SystemInfo { private String hostName = "Fruzhin"; private String hostVersion = "0.0.1"; - private static final DivLogger log = new DivLogger(); - public SystemInfo(ChainService chainService) { // this.role = network.getNodeRole().name(); this.chainService = chainService; @@ -37,12 +34,12 @@ public void logSystemInfo() { String labelEmoji = new String(Character.toChars(0x1F3F7)); String authEmoji = new String(Character.toChars(0x1F464)); - log.log(Level.INFO, lemonEmoji + "LimeChain Fruzhin"); - log.log(Level.INFO, pinEmoji + "Version: " + hostVersion); - log.log(Level.INFO, clipboardEmoji + "Chain specification: " + chainService.getChain().getValue()); - log.log(Level.INFO, labelEmoji + "Host name: " + hostName); -// log.log(Level.INFO, authEmoji + "Role: " + role); -// log.log(Level.INFO, "Local node identity is: " + hostIdentity); - log.log(Level.INFO, "Operating System: " + System.getProperty("os.name")); + log.fine(lemonEmoji + "LimeChain Fruzhin"); + log.fine(pinEmoji + "Version: " + hostVersion); + log.fine(clipboardEmoji + "Chain specification: " + chainService.getChain().getValue()); + log.fine(labelEmoji + "Host name: " + hostName); +// log.fine(authEmoji + "Role: " + role); +// log.fine("Local node identity is: " + hostIdentity); + log.fine("Operating System: " + System.getProperty("os.name")); } } diff --git a/src/main/java/com/limechain/sync/warpsync/WarpSyncMachine.java b/src/main/java/com/limechain/sync/warpsync/WarpSyncMachine.java index 6c18db688..254fbd56d 100644 --- a/src/main/java/com/limechain/sync/warpsync/WarpSyncMachine.java +++ b/src/main/java/com/limechain/sync/warpsync/WarpSyncMachine.java @@ -12,9 +12,9 @@ import com.limechain.sync.warpsync.action.RpcFallbackAction; import com.limechain.sync.warpsync.action.WarpSyncAction; import com.limechain.tuple.Pair; -import com.limechain.utils.DivLogger; import lombok.Getter; import lombok.Setter; +import lombok.extern.java.Log; import java.math.BigInteger; import java.util.ArrayList; @@ -22,14 +22,12 @@ import java.util.List; import java.util.PriorityQueue; import java.util.Queue; -import java.util.logging.Level; @Getter @Setter +@Log public class WarpSyncMachine { - private static final DivLogger log = new DivLogger(); - private Queue fragmentsQueue; private WarpSyncAction warpSyncAction; private boolean isProtocolSync; @@ -106,7 +104,7 @@ private void finishWarpSync() { syncState.persistState(isProtocolSync, chainService.getChain().getId()); System.out.println("Warp sync finished."); - log.log(Level.INFO, "Highest known block at #" + syncState.getLastFinalizedBlockNumber()); + log.info("Highest known block at #" + syncState.getLastFinalizedBlockNumber()); onFinishCallbacks.forEach(Runnable::run); networkService.sendBlockAnnounceHandshake(); diff --git a/src/main/java/com/limechain/utils/DivLogger.java b/src/main/java/com/limechain/utils/DivLogger.java deleted file mode 100644 index 4e96bfb50..000000000 --- a/src/main/java/com/limechain/utils/DivLogger.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.limechain.utils; - -import org.teavm.jso.dom.html.HTMLDocument; - -import java.util.logging.Level; - -public class DivLogger { - public void log(String text){ - var document = HTMLDocument.current(); - var div = document.createElement("div"); - div.appendChild(document.createTextNode(text)); - document.getBody().appendChild(div); - } - - public void log(Level info, String text) { - log(info + " " + text); - } -}