From b10824bb5769c4abb93e3451673b88efdfb9d467 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 14 Sep 2018 14:33:49 +1200 Subject: Log using slf4j and java logging --- src/org/traccar/MainEventHandler.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/MainEventHandler.java') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 49694aaff..b24edf28e 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.socket.DatagramChannel; import io.netty.handler.timeout.IdleStateEvent; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.Position; import java.sql.SQLException; @@ -31,6 +32,8 @@ import java.util.Set; public class MainEventHandler extends ChannelInboundHandlerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(GeocoderHandler.class); + private final Set connectionlessProtocols = new HashSet<>(); public MainEventHandler() { @@ -48,7 +51,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { try { Context.getDeviceManager().updateLatestPosition(position); } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId(); @@ -58,7 +61,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { s.append(formatChannel(ctx.channel())).append(" "); s.append("id: ").append(uniqueId); s.append(", time: ").append( - new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime())); + new SimpleDateFormat(Context.DATE_FORMAT).format(position.getFixTime())); s.append(", lat: ").append(String.format("%.5f", position.getLatitude())); s.append(", lon: ").append(String.format("%.5f", position.getLongitude())); if (position.getSpeed() > 0) { @@ -72,7 +75,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (cmdResult != null) { s.append(", result: ").append(cmdResult); } - Log.info(s.toString()); + LOGGER.info(s.toString()); Context.getStatisticsManager().registerMessageStored(position.getDeviceId()); } @@ -84,12 +87,12 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - Log.info(formatChannel(ctx.channel()) + " connected"); + LOGGER.info(formatChannel(ctx.channel()) + " connected"); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - Log.info(formatChannel(ctx.channel()) + " disconnected"); + LOGGER.info(formatChannel(ctx.channel()) + " disconnected"); closeChannel(ctx.channel()); BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) ctx.pipeline().get("objectDecoder"); @@ -101,14 +104,14 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - Log.warning(formatChannel(ctx.channel()) + " error", cause); + LOGGER.warn(formatChannel(ctx.channel()) + " error", cause); closeChannel(ctx.channel()); } @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { - Log.info(formatChannel(ctx.channel()) + " timed out"); + LOGGER.info(formatChannel(ctx.channel()) + " timed out"); closeChannel(ctx.channel()); } } -- cgit v1.2.3