Added NetLogServer class
This commit is contained in:
parent
0dfd6cc049
commit
4360a11357
7 changed files with 68 additions and 20 deletions
|
|
@ -60,7 +60,7 @@ public class LogUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the global log formatter to the specified one
|
* Sets the log formatter to all root Handlers
|
||||||
*
|
*
|
||||||
* @param f is the formatter class
|
* @param f is the formatter class
|
||||||
*/
|
*/
|
||||||
|
|
@ -72,7 +72,7 @@ public class LogUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the log formatter
|
* Adds the log formatter to all handlers in the namespace
|
||||||
*
|
*
|
||||||
* @param f is the formatter class
|
* @param f is the formatter class
|
||||||
*/
|
*/
|
||||||
|
|
@ -90,6 +90,14 @@ public class LogUtil {
|
||||||
setLevel("", level);
|
setLevel("", level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Addsd a Handler to the root namespace
|
||||||
|
*/
|
||||||
|
public static void addGlobalHandler(Handler handler){
|
||||||
|
Logger root = Logger.getLogger("");
|
||||||
|
root.addHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the log level for a specified class
|
* Sets the log level for a specified class
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,13 @@ import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.ProgressBar;
|
import javafx.scene.control.ProgressBar;
|
||||||
|
import javafx.scene.control.TableCell;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
|
||||||
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
@ -77,7 +79,7 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||||
// Connect to Server
|
// Connect to Server
|
||||||
try{
|
try{
|
||||||
net = new NetLogClient("localhost", 5050);
|
net = new NetLogClient("127.0.0.1", 5050);
|
||||||
net.addListener( this );
|
net.addListener( this );
|
||||||
status = Status.RUNNING;
|
status = Status.RUNNING;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public class NetLogServer extends Handler {
|
||||||
public NetLogServer(int port) {
|
public NetLogServer(int port) {
|
||||||
super();
|
super();
|
||||||
net = new NetLogNetwork(port);
|
net = new NetLogNetwork(port);
|
||||||
|
net.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -116,19 +116,22 @@ public class NetLogServer extends Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueMessage(Message log){
|
public void queueMessage(Message log){
|
||||||
|
synchronized(queue){
|
||||||
queue.add( log );
|
queue.add( log );
|
||||||
queue.notify();
|
queue.notify();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while( true ){
|
while( true ){
|
||||||
|
synchronized(queue){
|
||||||
while( !queue.isEmpty() ){
|
while( !queue.isEmpty() ){
|
||||||
Message msg = queue.poll();
|
Message msg = queue.poll();
|
||||||
out.writeObject( msg );
|
out.writeObject( msg );
|
||||||
}
|
}
|
||||||
queue.wait();
|
queue.wait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, null, e);
|
logger.log(Level.SEVERE, null, e);
|
||||||
|
|
@ -142,8 +145,8 @@ public class NetLogServer extends Handler {
|
||||||
try {
|
try {
|
||||||
out.close();
|
out.close();
|
||||||
s.close();
|
s.close();
|
||||||
queue = null;
|
|
||||||
threads.remove(this);
|
threads.remove(this);
|
||||||
|
queue = null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.log(Level.SEVERE, "Unable to close Client Socket", e);
|
logger.log(Level.SEVERE, "Unable to close Client Socket", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
|
|
||||||
|
|
||||||
/* LOG LEVELS */
|
/* LOG LEVELS */
|
||||||
|
.SEVERE {
|
||||||
|
-fx-control-inner-background: palevioletred;
|
||||||
|
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||||
|
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||||
|
}
|
||||||
.WARNING {
|
.WARNING {
|
||||||
-fx-control-inner-background: paleyellow;
|
-fx-control-inner-background: paleyellow;
|
||||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||||
}
|
}
|
||||||
|
.INFO { }
|
||||||
.FINE {
|
.FINE {
|
||||||
-fx-control-inner-background: skyblue;
|
-fx-control-inner-background: skyblue;
|
||||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||||
|
|
@ -23,8 +26,10 @@
|
||||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ERROR {
|
/* Clear empty rows */
|
||||||
-fx-control-inner-background: palevioletred;
|
.table-row-cell:empty {
|
||||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
-fx-background-color: null;
|
||||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
}
|
||||||
|
.table-row-cell:empty .table-cell {
|
||||||
|
-fx-border-width: 0px;
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +81,7 @@ public abstract class ThreadedTCPNetworkServer extends Thread{
|
||||||
else{
|
else{
|
||||||
ss = new ServerSocket( port );
|
ss = new ServerSocket( port );
|
||||||
}
|
}
|
||||||
|
logger.info("Listening for TCP Connections on port: "+port);
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
Socket s = ss.accept();
|
Socket s = ss.accept();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public class ThreadedUDPNetwork extends Thread{
|
||||||
protected ThreadedUDPNetworkThread thread = null;
|
protected ThreadedUDPNetworkThread thread = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new unicast Clien instance of the class
|
* Creates a new unicast Client instance of the class
|
||||||
*
|
*
|
||||||
* @param thread is the class that will handle incoming packets
|
* @param thread is the class that will handle incoming packets
|
||||||
* @throws SocketException
|
* @throws SocketException
|
||||||
|
|
|
||||||
29
src/zutil/test/NetLogServerTest.java
Normal file
29
src/zutil/test/NetLogServerTest.java
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package zutil.test;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
import zutil.log.net.NetLogServer;
|
||||||
|
|
||||||
|
public class NetLogServerTest {
|
||||||
|
public static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
LogUtil.setGlobalLevel(Level.FINEST);
|
||||||
|
LogUtil.addGlobalHandler(new NetLogServer(5050));
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
logger.log(Level.SEVERE, "Test Severe");
|
||||||
|
logger.log(Level.WARNING, "Test Warning");
|
||||||
|
logger.log(Level.INFO, "Test Info");
|
||||||
|
logger.log(Level.FINE, "Test Fine");
|
||||||
|
logger.log(Level.FINER, "Test Finer");
|
||||||
|
logger.log(Level.FINEST, "Test Finest");
|
||||||
|
|
||||||
|
logger.log(Level.SEVERE, "Test Exception", new Exception("Test"));
|
||||||
|
|
||||||
|
try{Thread.sleep(3000);}catch(Exception e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue