Added NetLogServer class

This commit is contained in:
Ziver Koc 2013-05-07 16:19:47 +00:00
parent 0dfd6cc049
commit 4360a11357
7 changed files with 68 additions and 20 deletions

View file

@ -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
*/
@ -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
*/
@ -90,6 +90,14 @@ public class LogUtil {
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
*/

View file

@ -35,11 +35,13 @@ import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.TableView;
import javafx.scene.control.Label;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.util.Callback;
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
private static final Logger logger = LogUtil.getLogger();
@ -77,7 +79,7 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
public void initialize(URL arg0, ResourceBundle arg1) {
// Connect to Server
try{
net = new NetLogClient("localhost", 5050);
net = new NetLogClient("127.0.0.1", 5050);
net.addListener( this );
status = Status.RUNNING;
}catch(Exception e){

View file

@ -49,7 +49,7 @@ public class NetLogServer extends Handler {
public NetLogServer(int port) {
super();
net = new NetLogNetwork(port);
net.start();
}
@ -116,19 +116,22 @@ public class NetLogServer extends Handler {
}
public void queueMessage(Message log){
queue.add( log );
queue.notify();
synchronized(queue){
queue.add( log );
queue.notify();
}
}
public void run() {
try {
while( true ){
while( !queue.isEmpty() ){
Message msg = queue.poll();
out.writeObject( msg );
synchronized(queue){
while( !queue.isEmpty() ){
Message msg = queue.poll();
out.writeObject( msg );
}
queue.wait();
}
queue.wait();
}
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
@ -142,8 +145,8 @@ public class NetLogServer extends Handler {
try {
out.close();
s.close();
queue = null;
threads.remove(this);
queue = null;
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to close Client Socket", e);
}

View file

@ -1,12 +1,15 @@
/* 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 {
-fx-control-inner-background: paleyellow;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}
.INFO { }
.FINE {
-fx-control-inner-background: skyblue;
-fx-accent: derive(-fx-control-inner-background, -40%);
@ -23,8 +26,10 @@
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}
.ERROR {
-fx-control-inner-background: palevioletred;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
/* Clear empty rows */
.table-row-cell:empty {
-fx-background-color: null;
}
.table-row-cell:empty .table-cell {
-fx-border-width: 0px;
}

View file

@ -81,6 +81,7 @@ public abstract class ThreadedTCPNetworkServer extends Thread{
else{
ss = new ServerSocket( port );
}
logger.info("Listening for TCP Connections on port: "+port);
while(true){
Socket s = ss.accept();

View file

@ -49,7 +49,7 @@ public class ThreadedUDPNetwork extends Thread{
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
* @throws SocketException

View 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){}
}
}
}