mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
Added start of basic logging using logback
This commit is contained in:
parent
fbb60cf9e3
commit
4b72d77ad4
@ -11,6 +11,7 @@
|
||||
<properties>
|
||||
<javafx.version>1.8</javafx.version>
|
||||
<jettyVersion>9.4.48.v20220622</jettyVersion>
|
||||
<logback.version>1.3.5</logback.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
@ -224,11 +225,12 @@
|
||||
<groupId>com.github.tulskiy</groupId>
|
||||
<artifactId>jkeymaster</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>2.0.0-alpha0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-artifact -->
|
||||
<dependency>
|
||||
@ -274,17 +276,32 @@
|
||||
<groupId>com.github.ganskef</groupId>
|
||||
<artifactId>littleproxy-mitm</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>G-Earth</groupId>
|
||||
<artifactId>G-Wasm-Minimal</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
@ -48,7 +48,13 @@ public class GEarth extends Application {
|
||||
stage = primaryStage;
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
|
||||
Parent root = loader.load();
|
||||
Parent root;
|
||||
try {
|
||||
root = loader.load();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
controller = loader.getController();
|
||||
controller.setStage(primaryStage);
|
||||
stage.initStyle(StageStyle.TRANSPARENT);
|
||||
|
@ -9,14 +9,17 @@ import gearth.protocol.connection.proxy.ProxyProvider;
|
||||
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxy;
|
||||
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxyServerCallback;
|
||||
import gearth.protocol.connection.proxy.nitro.websocket.NitroWebsocketProxy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCallback, StateChangeListener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NitroProxyProvider.class);
|
||||
|
||||
private final HProxySetter proxySetter;
|
||||
private final HStateSetter stateSetter;
|
||||
private final HConnection connection;
|
||||
@ -52,20 +55,27 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
|
||||
|
||||
connection.getStateObservable().addListener(this);
|
||||
|
||||
logger.info("Starting http proxy");
|
||||
|
||||
if (!nitroHttpProxy.start()) {
|
||||
System.out.println("Failed to start nitro proxy");
|
||||
logger.error("Failed to start nitro proxy");
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Starting websocket proxy");
|
||||
|
||||
if (!nitroWebsocketProxy.start()) {
|
||||
System.out.println("Failed to start nitro websocket proxy");
|
||||
logger.error("Failed to start nitro websocket proxy");
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
websocketPort = nitroWebsocketProxy.getPort();
|
||||
|
||||
logger.info("Websocket proxy is listening on port {}", websocketPort);
|
||||
logger.info("Nitro proxy started");
|
||||
|
||||
stateSetter.setState(HState.WAITING_FOR_CLIENT);
|
||||
}
|
||||
|
||||
@ -75,19 +85,25 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
|
||||
return;
|
||||
}
|
||||
|
||||
if (abortLock.compareAndSet(true, true)) {
|
||||
if (!abortLock.compareAndSet(false, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Aborting nitro proxy");
|
||||
|
||||
stateSetter.setState(HState.ABORTING);
|
||||
|
||||
new Thread(() -> {
|
||||
logger.info("Stopping nitro http proxy");
|
||||
|
||||
try {
|
||||
nitroHttpProxy.stop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.info("Stopping nitro websocket proxy");
|
||||
|
||||
try {
|
||||
nitroWebsocketProxy.stop();
|
||||
} catch (Exception e) {
|
||||
@ -97,6 +113,8 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
|
||||
stateSetter.setState(HState.NOT_CONNECTED);
|
||||
|
||||
connection.getStateObservable().removeListener(this);
|
||||
|
||||
logger.info("Nitro proxy stopped");
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,13 @@ import gearth.protocol.connection.*;
|
||||
import gearth.protocol.connection.proxy.nitro.NitroConstants;
|
||||
import gearth.protocol.connection.proxy.nitro.NitroProxyProvider;
|
||||
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -23,6 +22,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ServerEndpoint(value = "/")
|
||||
public class NitroWebsocketClient implements NitroSession {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketClient.class);
|
||||
|
||||
private final HProxySetter proxySetter;
|
||||
private final HStateSetter stateSetter;
|
||||
private final HConnection connection;
|
||||
@ -45,6 +46,8 @@ public class NitroWebsocketClient implements NitroSession {
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session) throws Exception {
|
||||
logger.info("WebSocket connection accepted");
|
||||
|
||||
activeSession = (JsrSession) session;
|
||||
activeSession.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
||||
|
||||
|
@ -6,8 +6,9 @@ import gearth.protocol.connection.proxy.nitro.NitroConstants;
|
||||
import gearth.protocol.packethandler.PacketHandler;
|
||||
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension;
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.websocket.*;
|
||||
import java.io.IOException;
|
||||
@ -16,6 +17,8 @@ import java.util.*;
|
||||
|
||||
public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketServer.class);
|
||||
|
||||
private static final HashSet<String> SKIP_HEADERS = new HashSet<>(Arrays.asList(
|
||||
"Sec-WebSocket-Extensions",
|
||||
"Sec-WebSocket-Key",
|
||||
@ -36,6 +39,8 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
||||
|
||||
public void connect(String websocketUrl, Map<String, List<String>> clientHeaders) throws IOException {
|
||||
try {
|
||||
logger.info("Connecting to origin websocket at {}", websocketUrl);
|
||||
|
||||
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
|
||||
|
||||
builder.extensions(Collections.singletonList(new JsrExtension(new ExtensionConfig("permessage-deflate;client_max_window_bits"))));
|
||||
@ -57,6 +62,8 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
||||
ClientEndpointConfig config = builder.build();
|
||||
|
||||
ContainerProvider.getWebSocketContainer().connectToServer(this, config, URI.create(websocketUrl));
|
||||
|
||||
logger.info("Connected to origin websocket");
|
||||
} catch (DeploymentException e) {
|
||||
throw new IOException("Failed to deploy websocket client", e);
|
||||
}
|
||||
|
16
G-Earth/src/main/resources/logback.xml
Normal file
16
G-Earth/src/main/resources/logback.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="debug">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
<logger name="com.tulskiy.keymaster" level="WARN"/>
|
||||
<logger name="io.netty" level="WARN"/>
|
||||
<logger name="org.littleshoot" level="OFF"/>
|
||||
<logger name="org.eclipse.jetty" level="WARN"/>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user