diff --git a/no2all-react-nostr/pom.xml b/no2all-react-nostr/pom.xml index ff6665a..024bae8 100644 --- a/no2all-react-nostr/pom.xml +++ b/no2all-react-nostr/pom.xml @@ -21,5 +21,10 @@ no2all-wire-ojw test + + ch.qos.logback + logback-classic + test + \ No newline at end of file diff --git a/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/NoStrRtsServer.java b/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/NoStrRtsServer.java index 1fb9588..9a19f50 100644 --- a/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/NoStrRtsServer.java +++ b/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/NoStrRtsServer.java @@ -60,7 +60,7 @@ public class NoStrRtsServer implements No2AllReactTypeScript { NoStrFirePipe pipeReader = NoStr.FACTORY.pipeReaderRelay(reason -> { react.fire(socketSlot, No2AllActServerSocketClose.ofRefuse(reason)); }, message -> { - react.fire(serverSlot, message); + react.fire(socketSlot, message); }); react.registrate(socketSlot, No2AllArtServerSocketOnMessage.class, v -> { pipeReader.onFire(v.getData().getMessage()); diff --git a/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/relay/NoStrRtsServerRelay.java b/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/relay/NoStrRtsServerRelay.java index ab3bc9b..772c430 100644 --- a/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/relay/NoStrRtsServerRelay.java +++ b/no2all-react-nostr/src/main/java/love/distributedrebirth/no2all/react/nostr/server/relay/NoStrRtsServerRelay.java @@ -1,5 +1,7 @@ package love.distributedrebirth.no2all.react.nostr.server.relay; +import java.util.logging.Logger; + import love.distributedrebirth.no2all.nostr.model.event.NoStrEvent; import love.distributedrebirth.no2all.nostr.model.event.NoStrEventSignature; import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToClientOk; @@ -18,11 +20,13 @@ import love.distributedrebirth.no2all.react.wire.server.No2AllRtsServer; public class NoStrRtsServerRelay implements No2AllReactTypeScript { public static final No2AllReactSlot API = No2AllReactSlot.ofClass(NoStrRtsServerRelay.class); + private static final Logger logger = Logger.getLogger(NoStrRtsServerRelay.class.getName()); @Override public void onEvent(No2AllReactSlotSignal signal) { No2AllReact react = signal.getReact(); react.claim(API); + react.claimOut(API, NoStrArtServerRelayStoreEvent.class); react.requireSlot(API, NoStrRtsServer.API); react.registrate(No2AllRtsServer.API, No2AllArtServer.class, artServer -> { No2AllReactSlot serverSlot = artServer.getData().getSlot(); @@ -50,7 +54,7 @@ public class NoStrRtsServerRelay implements No2AllReactTypeScript { eventReason = NoStrImplMessageOkReason.INVALID; } - System.out.println("Validate event: " + eventSaved + " eventId: " + event.getId()); + logger.fine("Validate event: " + eventSaved + " eventId: " + event.getId()); if (eventSaved) { diff --git a/no2all-react-nostr/src/test/java/love/distributedrebirth/no2all/react/nostr/client/NoStrClientTest.java b/no2all-react-nostr/src/test/java/love/distributedrebirth/no2all/react/nostr/client/NoStrClientTest.java index 020a237..acb52e9 100644 --- a/no2all-react-nostr/src/test/java/love/distributedrebirth/no2all/react/nostr/client/NoStrClientTest.java +++ b/no2all-react-nostr/src/test/java/love/distributedrebirth/no2all/react/nostr/client/NoStrClientTest.java @@ -10,7 +10,7 @@ import love.distributedrebirth.no2all.nostr.fire.NoStrFireWaterBoiler; import love.distributedrebirth.no2all.nostr.model.NoStrIdentity; import love.distributedrebirth.no2all.nostr.model.NoStrIdentityPrivateKey; import love.distributedrebirth.no2all.nostr.model.event.NoStrEvent; -import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToRelayClose; +import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToRelayEvent; import love.distributedrebirth.no2all.nostr.nip.NoStrImplEventKind; import love.distributedrebirth.no2all.react.No2AllReactSlot; import love.distributedrebirth.no2all.react.warp.No2AllReactWarpCore; @@ -21,18 +21,17 @@ import love.distributedrebirth.no2all.react.wire.client.No2AllActClientConnect; import love.distributedrebirth.no2all.react.wire.client.No2AllArtClient; import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnClose; import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnError; +import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnMessage; import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnOpen; +import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnStart; import love.distributedrebirth.no2all.react.wire.client.No2AllRtsClient; import love.distributedrebirth.no2all.wire.ojw.OjwWireClientEndpoint; public class NoStrClientTest { - private final static NoStrIdentity SENDER = new NoStrIdentity(NoStrIdentityPrivateKey.ofRandom()); - // private final static Map RELAYS = Map.of("brb", "brb.io", - // "damus", "relay.damus.io", "ZBD", "nostr.zebedee.cloud", "taxi", - // "relay.taxi", "vision", "relay.nostr.vision"); - public static void main(String[] args) throws Exception { + ExecutorService executor = Executors.newFixedThreadPool(10); + NoStrIdentity nid = new NoStrIdentity(NoStrIdentityPrivateKey.ofRandom()); No2AllReactWarpCore react = new No2AllReactWarpCore(); react.load(new No2AllRtsWarpSpeedMonitor()); react.load(new No2AllRtsClient()); @@ -40,35 +39,55 @@ public class NoStrClientTest { react.registrate(No2AllRtsClient.API, No2AllArtClient.class, v -> { No2AllReactSlot clientSlot = v.getData().getSlot(); - System.out.println("NoStrClient connect"); + System.out.println("NoStrClient created: " + clientSlot.getSlotPath()); react.registrate(clientSlot, No2AllArtClientOnError.class, x -> { System.out.println("NoStrClient socket error: " + x.getData().getError().getMessage()); }); react.registrate(clientSlot, No2AllArtClientOnClose.class, x -> { - System.out.println("NoStrClient socket close"); + System.out.println("NoStrClient socket close: " + x.getData().getCode() + " " + x.getData().getReason()); }); react.registrate(clientSlot, No2AllArtClientOnOpen.class, x -> { System.out.println("NoStrClient socket open"); - react.fire(clientSlot, new NoStrMsgToRelayClose("give-me-error")); + + executor.submit(() -> { + try { + for (int i = 0; i < 10; i++) { + NoStrFireWaterBoiler userBoiler = NoStr.FACTORY.boiler(nid); + NoStrEvent event = userBoiler.smoker() + .tagSubject("Reply to all") + .tagR("") + .burn() + .water(NoStrImplEventKind.TEXT_NOTE, "Hello world:"+i); + + System.out.println("send msg"); + NoStrMsgToRelayEvent msg = new NoStrMsgToRelayEvent(event); + react.fire(clientSlot, msg); + Thread.sleep(1000); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + }); + }); + + react.registrate(clientSlot, No2AllArtClientOnMessage.class, y -> { + System.out.println("NoStrClient got msg1: " + y.getData().getMessage()); + }); + // Todo "OnStart" is not working... + react.registrate(clientSlot, No2AllArtClientOnStart.class, x -> { + System.out.println("NoStrClient socket start"); }); react.fire(clientSlot, new No2AllActClientConnect()); }); - - OjwWireClientEndpoint clientEndpoint = new OjwWireClientEndpoint(new URI("ws://localhost:8080")); + + OjwWireClientEndpoint clientEndpoint = new OjwWireClientEndpoint(new URI("ws://localhost:8080/event")); System.out.println("NoStrClient start"); react.fire(No2AllRtsClient.API, new No2AllActClient(clientEndpoint)); - - OjwWireClientEndpoint clientEndpoint2 = new OjwWireClientEndpoint(new URI("ws://localhost:8080")); - System.out.println("NoStrClient start2"); - react.fire(No2AllRtsClient.API, new No2AllActClient(clientEndpoint2)); - - for (int i = 0; i < 100; i++) { - react.fire(No2AllRtsClient.API, SENDER); - Thread.sleep(100); - } - - Thread.sleep(500); - + + Thread.sleep(30000); + + executor.shutdown(); + executor.awaitTermination(60, TimeUnit.SECONDS); Thread exitTimer = new Thread(() -> { try { Thread.sleep(2000); @@ -82,29 +101,4 @@ public class NoStrClientTest { }); exitTimer.start(); } - - public static void main2(String[] args) throws Exception { - - - - ExecutorService executor = Executors.newFixedThreadPool(10); - executor.submit(() -> { - try { - NoStrFireWaterBoiler userBoiler = NoStr.FACTORY.boiler(SENDER); - NoStrEvent event = userBoiler.smoker() - .tagSubject("Reply to all") - .tagR("") - .burn() - .water(NoStrImplEventKind.TEXT_NOTE, "Hello world"); - - System.out.println(event); - // GenericMessage message = new EventMessage(event); - // CLIENT.send(message); - } catch (Exception ex) { - ex.printStackTrace(); - } - }); - executor.shutdown(); - executor.awaitTermination(60, TimeUnit.SECONDS); - } } diff --git a/no2all-react-wire/src/main/java/love/distributedrebirth/no2all/react/wire/server/No2AllRtsServerLog.java b/no2all-react-wire/src/main/java/love/distributedrebirth/no2all/react/wire/server/No2AllRtsServerLog.java index d0c3d46..93990f0 100644 --- a/no2all-react-wire/src/main/java/love/distributedrebirth/no2all/react/wire/server/No2AllRtsServerLog.java +++ b/no2all-react-wire/src/main/java/love/distributedrebirth/no2all/react/wire/server/No2AllRtsServerLog.java @@ -1,6 +1,9 @@ package love.distributedrebirth.no2all.react.wire.server; import love.distributedrebirth.no2all.react.No2AllReactSlotLoad; + +import java.util.logging.Logger; + import love.distributedrebirth.no2all.react.No2AllReact; import love.distributedrebirth.no2all.react.No2AllReactSlot; import love.distributedrebirth.no2all.react.No2AllReactSlotSignal; @@ -9,6 +12,7 @@ import love.distributedrebirth.no2all.react.No2AllReactTypeScript; public class No2AllRtsServerLog implements No2AllReactTypeScript { public static final No2AllReactSlot API = No2AllReactSlot.ofClass(No2AllRtsServerLog.class); + private static final Logger logger = Logger.getLogger(No2AllRtsServerLog.class.getName()); @Override public void onEvent(No2AllReactSlotSignal signal) { @@ -17,16 +21,16 @@ public class No2AllRtsServerLog implements No2AllReactTypeScript { react.registrate(No2AllRtsServer.API, No2AllArtServer.class, artServer -> { No2AllReactSlot serverSlot = artServer.getData().getSlot(); react.registrate(serverSlot, No2AllActServerBroadcastMessage.class, v -> { - System.out.println("No2AllRtsServerLog.broadcastMessage: " + v.getData().getMessage()); + logger.info("broadcastMessage: " + v.getData().getMessage()); }); react.registrate(serverSlot, No2AllArtServerSocket.class, v -> { No2AllReactSlot socketSlot = v.getData().getSlot(); String wireId = socketSlot.getSlotSlug(); react.registrate(socketSlot, No2AllArtServerSocketOnMessage.class, z -> { - System.out.println("No2AllRtsServerLog."+wireId+".socketOnMessage: " + z.getData().getMessage()); + logger.info(wireId+".socketOnMessage: " + z.getData().getMessage()); }); react.registrate(socketSlot, No2AllActServerSocketSendMessage.class, z -> { - System.out.println("No2AllRtsServerLog."+wireId+".socketSendMessage: " + z.getData().getMessage()); + logger.info(wireId+".socketSendMessage: " + z.getData().getMessage()); }); }); }); diff --git a/no2all-react/src/main/java/love/distributedrebirth/no2all/react/warp/No2AllReactWarpCore.java b/no2all-react/src/main/java/love/distributedrebirth/no2all/react/warp/No2AllReactWarpCore.java index 9428708..1f1f266 100644 --- a/no2all-react/src/main/java/love/distributedrebirth/no2all/react/warp/No2AllReactWarpCore.java +++ b/no2all-react/src/main/java/love/distributedrebirth/no2all/react/warp/No2AllReactWarpCore.java @@ -75,10 +75,12 @@ public class No2AllReactWarpCore implements No2AllReact { try { toWarpFuel(slot).fire(event, slot); - List backlog2 = new ArrayList<>(backlog); - backlog.clear(); - for (BacklogEvent next : backlog2) { - toWarpFuel(next.slot).fire(next.event, next.slot); + while (!backlog.isEmpty()) { + List backlog2 = new ArrayList<>(backlog); + backlog.clear(); + for (BacklogEvent next : backlog2) { + toWarpFuel(next.slot).fire(next.event, next.slot); + } } } finally { currentEvent = null; diff --git a/no2all-wire-jre/src/main/java/love/distributedrebirth/no2all/wire/jre/JreWireClientHandler.java b/no2all-wire-jre/src/main/java/love/distributedrebirth/no2all/wire/jre/JreWireClientHandler.java index a6ebf83..2d50112 100644 --- a/no2all-wire-jre/src/main/java/love/distributedrebirth/no2all/wire/jre/JreWireClientHandler.java +++ b/no2all-wire-jre/src/main/java/love/distributedrebirth/no2all/wire/jre/JreWireClientHandler.java @@ -13,6 +13,7 @@ public final class JreWireClientHandler implements WebSocket.Listener { protected JreWireClientHandler(WireClientHandler handler) { this.handler = handler; + this.handler.onStart(); } @Override diff --git a/no2all-wire-ojw/src/main/java/love/distributedrebirth/no2all/wire/ojw/OjwWireClient.java b/no2all-wire-ojw/src/main/java/love/distributedrebirth/no2all/wire/ojw/OjwWireClient.java index f76fccb..9103fe5 100644 --- a/no2all-wire-ojw/src/main/java/love/distributedrebirth/no2all/wire/ojw/OjwWireClient.java +++ b/no2all-wire-ojw/src/main/java/love/distributedrebirth/no2all/wire/ojw/OjwWireClient.java @@ -11,8 +11,9 @@ public class OjwWireClient implements WireClient { private final OjwWireClientHandler handler; - protected OjwWireClient(URI uri, Map headers, int timeoutMs, WireClientHandler handler) { - this.handler = new OjwWireClientHandler(uri, headers, timeoutMs, handler); + protected OjwWireClient(URI uri, Map headers, int timeoutMs, WireClientHandler wireHandler) { + this.handler = new OjwWireClientHandler(uri, headers, timeoutMs, wireHandler); + wireHandler.onStart(); } public OjwWireClientHandler getHandler() { diff --git a/no2all-zerofungus/conf/logback-server-console.xml b/no2all-zerofungus/conf/logback-server-console.xml index 918cbc0..016b04a 100644 --- a/no2all-zerofungus/conf/logback-server-console.xml +++ b/no2all-zerofungus/conf/logback-server-console.xml @@ -25,5 +25,6 @@ + diff --git a/no2all-zerofungus/pom.xml b/no2all-zerofungus/pom.xml index 518f989..a80b90b 100644 --- a/no2all-zerofungus/pom.xml +++ b/no2all-zerofungus/pom.xml @@ -16,6 +16,10 @@ ${project.groupId} no2all-wire-jetty + + org.eclipse.parsson + parsson + ch.qos.logback logback-classic diff --git a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServer.java b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServer.java new file mode 100644 index 0000000..66f2b49 --- /dev/null +++ b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServer.java @@ -0,0 +1,56 @@ +package love.distributedrebirth.no2all.zerofungus; + +import java.io.StringWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.logging.Logger; + +import javax.sql.DataSource; + +import jakarta.json.Json; +import jakarta.json.JsonWriter; +import love.distributedrebirth.no2all.nostr.model.event.NoStrEvent; +import love.distributedrebirth.no2all.react.No2AllReact; +import love.distributedrebirth.no2all.react.No2AllReactSlot; +import love.distributedrebirth.no2all.react.No2AllReactSlotLoad; +import love.distributedrebirth.no2all.react.No2AllReactSlotSignal; +import love.distributedrebirth.no2all.react.No2AllReactTypeScript; +import love.distributedrebirth.no2all.react.nostr.server.relay.NoStrArtServerRelayStoreEvent; +import love.distributedrebirth.no2all.react.nostr.server.relay.NoStrRtsServerRelay; + +public class ZFunRtsServer implements No2AllReactTypeScript { + + public static final No2AllReactSlot API = No2AllReactSlot.ofClass(ZFunRtsServer.class); + private static final Logger logger = Logger.getLogger(ZFunRtsServer.class.getName()); + + @Override + public void onEvent(No2AllReactSlotSignal signal) { + No2AllReact react = signal.getReact(); + react.claim(API); + + DataSource ds = react.service(DataSource.class); + react.registrate(NoStrRtsServerRelay.API, NoStrArtServerRelayStoreEvent.class, storeEvent -> { + logger.info("Store event: " + storeEvent.getData().getEvent().getId().getHexDipavali()); + NoStrEvent event = storeEvent.getData().getEvent(); + StringWriter jsonStr = new StringWriter(); + try (JsonWriter writer = Json.createWriter(jsonStr)) { + writer.write(event.toBible()); + } + try (Connection conn = ds.getConnection()) { + String sql = "INSERT INTO \"ᔆʸᔆᐪᓫᔿ\".\"ᔆᐪᣔᒼᒽᑉ\" (\"ᑊᑊᐣ\",\"ᣖᓑᒃᒽᑉᓫᔾ\",\"ᒼᣗᓫᣔᐪᓫᐝᒄᐪ\",\"ᑊᑉᑊᣕᒄ\",\"ᒄᓫᒻᐪᣔᕐ\",\"ᓫᕁᣖᑊᣗᓫᐝᒄᐪ\",\"ᣗᣔᒡᒢ\") VALUES (?,?,?,?,?,?,?)"; + PreparedStatement prep = conn.prepareStatement(sql); + prep.setString(1, event.getId().getHex()); + prep.setString(2, event.getPayload().getPublicKey().getHex()); + prep.setDate(3, new java.sql.Date(event.getPayload().getCreatedAt().toEpochMilli())); + prep.setInt(4, event.getPayload().getKind().getNumber()); + prep.setString(5, null); // del tag + prep.setString(6, null); // exp date + prep.setString(7, jsonStr.toString()); + prep.executeUpdate(); + } catch (SQLException e) { + logger.warning(e.getMessage()); + } + }); + } +} diff --git a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunServer.java b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServerBooted.java similarity index 81% rename from no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunServer.java rename to no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServerBooted.java index 6327224..564b8c0 100644 --- a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunServer.java +++ b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZFunRtsServerBooted.java @@ -7,17 +7,14 @@ import love.distributedrebirth.no2all.react.No2AllReactSlotLoad; import love.distributedrebirth.no2all.react.No2AllReactSlotSignal; import love.distributedrebirth.no2all.react.No2AllReactTypeScript; -public class ZFunServer implements No2AllReactTypeScript { +public class ZFunRtsServerBooted implements No2AllReactTypeScript { - public static final No2AllReactSlot API = No2AllReactSlot.ofClass(ZFunServer.class); - private static final Logger logger = Logger.getLogger(ZFunServer.class.getName()); + public static final No2AllReactSlot API = No2AllReactSlot.ofClass(ZFunRtsServerBooted.class); + private static final Logger logger = Logger.getLogger(ZFunRtsServerBooted.class.getName()); @Override public void onEvent(No2AllReactSlotSignal signal) { signal.getReact().claim(API); - - // TODO: reg and refire events - logger.info("╔═╗┌─┐┬─┐┌─┐ .╔═╗┬ ┬┌┐┌╔═╗┬ ┬┌─┐"); logger.info("╔═╝├┤ ├┬┘│ │ . ╠╣ │ ││││║ ╦│ │└─┐"); logger.info("╚═╝└─┘┴└─└─┘. ╚ └─┘┘└┘╚═╝└─┘└─┘"); diff --git a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZeroFungus.java b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZeroFungus.java index 8d05ca6..622a907 100644 --- a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZeroFungus.java +++ b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/ZeroFungus.java @@ -1,7 +1,12 @@ package love.distributedrebirth.no2all.zerofungus; +import love.distributedrebirth.no2all.react.nostr.client.NoStrRtsClient; +import love.distributedrebirth.no2all.react.nostr.server.NoStrRtsServer; +import love.distributedrebirth.no2all.react.nostr.server.relay.NoStrRtsServerRelay; +import love.distributedrebirth.no2all.react.nostr.server.relay.NoStrRtsServerRelaySubs; import love.distributedrebirth.no2all.react.warp.No2AllReactWarpCore; import love.distributedrebirth.no2all.react.warp.No2AllRtsWarpSpeedMonitor; +import love.distributedrebirth.no2all.react.wire.client.No2AllRtsClient; import love.distributedrebirth.no2all.react.wire.server.No2AllRtsServer; import love.distributedrebirth.no2all.react.wire.server.No2AllRtsServerLog; import love.distributedrebirth.no2all.zerofungus.service.ZFunRtsConfigJetty; @@ -23,14 +28,29 @@ public enum ZeroFungus /*implements BãßBȍőnAbacusInstanceMBeanʸᴰ { - No2AllReactSlot serverSlot = artServer.getData().getSlot(); - react.registrate(serverSlot, No2AllArtServerSocket.class, artSocket -> { - No2AllReactSlot socketSlot = artSocket.getData().getSlot(); - react.registrate(socketSlot, No2AllArtServerSocketOnMessage.class, artMsg -> { - react.fire(socketSlot, - new No2AllActServerSocketSendMessage("RE: " + artMsg.getData().getMessage())); - }); - }); - }); react.fire(No2AllRtsServer.API, new No2AllActServer(endpoint1)); react.fire(No2AllRtsServer.API, new No2AllActServer(endpoint2)); react.fire(No2AllRtsServer.API, new No2AllActServer(endpoint3)); } }); try { - logger.info("start"); + logger.info("start jetty"); server.start(); - logger.info("start done"); + logger.info("jetty started"); } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/service/ZFunRtsConfigLogger.java b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/service/ZFunRtsConfigLogger.java index 7647ae8..ebeaeab 100644 --- a/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/service/ZFunRtsConfigLogger.java +++ b/no2all-zerofungus/src/main/java/love/distributedrebirth/no2all/zerofungus/service/ZFunRtsConfigLogger.java @@ -1,7 +1,5 @@ package love.distributedrebirth.no2all.zerofungus.service; -import java.io.File; -import java.net.MalformedURLException; import java.util.logging.Logger; import org.slf4j.LoggerFactory; @@ -20,32 +18,26 @@ public class ZFunRtsConfigLogger implements No2AllReactTypeScript { @Override public void onEvent(No2AllReactSlotSignal signal) { - if (System.getProperty("logback.configurationFile") != null) { - File logConfig = null; + if (System.getProperty("logback.configurationFile") == null) { + String logConfig = null; if (System.getProperty("java.class.path").contains("classes")) { - logConfig = new File("conf/logback-server-console.xml"); + logConfig = "conf/logback-server-console.xml"; } else { - logConfig = new File("conf/logback-server.xml"); - } - try { - System.setProperty("logback.configurationFile", logConfig.toURI().toURL().toExternalForm()); - } catch (MalformedURLException e) { - e.printStackTrace(); + logConfig = "conf/logback-server.xml"; } + System.setProperty("logback.configurationFile", logConfig); } - System.setProperty("logback.statusListenerClass",NopStatusListener.class.getName()); - - System.setProperty("logback.configurationFile","conf/logback-server-console.xml"); - org.slf4j.Logger logger2 = LoggerFactory.getLogger("MyTest"); - logger2.debug("Hello world."); + if (System.getProperty("logback.statusListenerClass") == null) { + System.setProperty("logback.statusListenerClass",NopStatusListener.class.getName()); + } + org.slf4j.Logger logger2 = LoggerFactory.getLogger(ZFunRtsConfigLogger.class); + logger2.info("Logging configured."); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); - logger.info("Logging configured"); - logger.info(" ╦┌─┐╔╦╗╔╦╗┬ ┬ ╔═╗┌─┐╦ ╦╔═╗┬─┐┌┬┐"); - logger.info(" ║├┤ ║ ║ └┬┘ ╠═╝│ │║║║║╣ ├┬┘ ││"); - logger.info("╚╝└─┘ ╩ ╩ ┴ ╩ └─┘╚╩╝╚═╝┴└──┴┘"); - + logger.info(" ╦┬ ┬╦ ╦═╗┌─┐╦ ╦┬╦═╗┌─┐╔╦╗"); + logger.info(" ║│ │║ ╠╦╝├┤ ║║║│╠╦╝├┤ ║║"); + logger.info("╚╝└─┘╩═╝ ╩╚═└─┘╚╩╝┴╩╚═└─┘═╩╝"); //https://patorjk.com/software/taag // Calvin S }