aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-12-18 22:31:16 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-12-18 22:31:16 +1300
commitf72eade8742022502e69b300296c8ac1fbf35b25 (patch)
tree4ae108a169b51dbb36e2789f367dac77310ccbc3 /src
parent34923934e0ee7d707aa9ffef2712942115236472 (diff)
downloadtraccar-server-f72eade8742022502e69b300296c8ac1fbf35b25.tar.gz
traccar-server-f72eade8742022502e69b300296c8ac1fbf35b25.tar.bz2
traccar-server-f72eade8742022502e69b300296c8ac1fbf35b25.zip
Couple of small changes
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/GenericPipelineFactory.java20
-rw-r--r--src/org/traccar/Server.java9
-rw-r--r--src/org/traccar/helper/Log.java4
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java36
4 files changed, 47 insertions, 22 deletions
diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/GenericPipelineFactory.java
index 3d20ec433..556d86e1d 100644
--- a/src/org/traccar/GenericPipelineFactory.java
+++ b/src/org/traccar/GenericPipelineFactory.java
@@ -17,6 +17,7 @@ package org.traccar;
import java.net.InetSocketAddress;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.logging.LoggingHandler;
import org.jboss.netty.handler.timeout.IdleStateHandler;
@@ -63,22 +64,19 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory {
public void log(ChannelEvent e) {
if (e instanceof MessageEvent) {
MessageEvent event = (MessageEvent) e;
- String msg = "[" + ((InetSocketAddress) e.getChannel().getLocalAddress()).getPort() + " - ";
- msg += ((InetSocketAddress) event.getRemoteAddress()).getAddress().getHostAddress() + "]";
+ StringBuilder msg = new StringBuilder();
+
+ msg.append("[").append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort()).append(" - ");
+ msg.append(((InetSocketAddress) event.getRemoteAddress()).getAddress().getHostAddress()).append("]");
// Append hex message
if (event.getMessage() instanceof ChannelBuffer) {
- ChannelBuffer buffer = (ChannelBuffer) event.getMessage();
- msg += " - (HEX: ";
- for (int i = buffer.readerIndex(); i < buffer.writerIndex(); i++) {
- byte b = buffer.getByte(i);
- msg += HEX_CHARS.charAt((b & 0xf0) >> 4);
- msg += HEX_CHARS.charAt((b & 0x0F));
- }
- msg += ")";
+ msg.append(" - (HEX: ");
+ msg.append(ChannelBuffers.hexDump((ChannelBuffer) event.getMessage()));
+ msg.append(")");
}
- Log.fine(msg);
+ Log.fine(msg.toString());
} else if (e instanceof ExceptionEvent) {
ExceptionEvent event = (ExceptionEvent) e;
Log.warning(event.getCause().toString());
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index 506513b60..2167a7933 100644
--- a/src/org/traccar/Server.java
+++ b/src/org/traccar/Server.java
@@ -28,8 +28,10 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
+import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+import java.util.logging.Logger;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelPipeline;
@@ -200,7 +202,12 @@ public class Server {
}
});
- // NOTE: Console logger level will remain INFO
+ // Remove old logging handlers
+ Handler[] handlers = Logger.getLogger("").getHandlers();
+ for(Handler handler : handlers) {
+ Logger.getLogger("").removeHandler(handler);
+ }
+
Log.getLogger().setLevel(Level.ALL);
Log.getLogger().addHandler(file);
}
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index 69eea6579..03de36c46 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -22,12 +22,14 @@ import java.util.logging.Logger;
* Logger
*/
public class Log {
+
+ private static String TRACCAR_LOGGER_NAME = "traccar";
/**
* Return global logger
*/
public static Logger getLogger() {
- return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+ return Logger.getLogger(TRACCAR_LOGGER_NAME);
}
private static void write(Level level, String msg) {
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 64aca8157..35db6e113 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -47,15 +47,17 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
/*
* Message types
*/
- static final int MSG_NULL = 0;
- static final int MSG_IDENT = 1;
- static final int MSG_IDENT_FULL = 2;
- static final int MSG_POINT = 10;
- static final int MSG_LOG_SYNC = 100;
- static final int MSG_LOGMSG = 101;
- static final int MSG_TEXT = 102;
- static final int MSG_ALARM = 200;
- static final int MSG_ALARM_RECIEVED = 201;
+ private static final int MSG_NULL = 0;
+ private static final int MSG_IDENT = 1;
+ private static final int MSG_IDENT_FULL = 2;
+ private static final int MSG_POINT = 10;
+ private static final int MSG_LOG_SYNC = 100;
+ private static final int MSG_LOGMSG = 101;
+ private static final int MSG_TEXT = 102;
+ private static final int MSG_ALARM = 200;
+ private static final int MSG_ALARM_RECIEVED = 201;
+
+ private static final String HEX_CHARS = "0123456789ABCDEF";
/**
* Decode message
@@ -150,12 +152,28 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
// CAN adapter
if ((extraFlags & 0x2) == 0x2) {
int size = buf.readUnsignedShort();
+ extendedInfo.append("<can>");
+ extendedInfo.append(buf.toString(buf.readerIndex(), size, Charset.defaultCharset()));
+ extendedInfo.append("</can>");
buf.skipBytes(size);
}
// Passenger sensor
if ((extraFlags & 0x4) == 0x4) {
int size = buf.readUnsignedShort();
+
+ // Convert binary data to hex
+ StringBuilder hex = new StringBuilder();
+ for (int i = buf.readerIndex(); i < buf.readerIndex() + size; i++) {
+ byte b = buf.getByte(i);
+ hex.append(HEX_CHARS.charAt((b & 0xf0) >> 4));
+ hex.append(HEX_CHARS.charAt((b & 0x0F)));
+ }
+
+ extendedInfo.append("<passenger>");
+ extendedInfo.append(hex);
+ extendedInfo.append("</passenger>");
+
buf.skipBytes(size);
}