diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-09-14 14:33:49 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-09-14 14:33:49 +1200 |
commit | b10824bb5769c4abb93e3451673b88efdfb9d467 (patch) | |
tree | c4d04ed2f19d5758a75b702467dbc051c5d0511c /src/org | |
parent | e331573c0df7467fd36ae3eba3c259ed9b1d9253 (diff) | |
download | trackermap-server-b10824bb5769c4abb93e3451673b88efdfb9d467.tar.gz trackermap-server-b10824bb5769c4abb93e3451673b88efdfb9d467.tar.bz2 trackermap-server-b10824bb5769c4abb93e3451673b88efdfb9d467.zip |
Log using slf4j and java logging
Diffstat (limited to 'src/org')
89 files changed, 495 insertions, 428 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 6269fb8cc..4cf5d7a98 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -29,6 +29,8 @@ import io.netty.channel.ChannelPromise; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.handler.timeout.IdleStateHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.events.CommandResultEventHandler; import org.traccar.events.DriverEventHandler; import org.traccar.events.FuelDropEventHandler; @@ -38,7 +40,6 @@ import org.traccar.events.MaintenanceEventHandler; import org.traccar.events.MotionEventHandler; import org.traccar.events.OverspeedEventHandler; import org.traccar.events.AlertEventHandler; -import org.traccar.helper.Log; import org.traccar.processing.ComputedAttributesHandler; import org.traccar.processing.CopyAttributesHandler; @@ -46,6 +47,8 @@ import java.net.InetSocketAddress; public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { + private static final Logger LOGGER = LoggerFactory.getLogger(BasePipelineFactory.class); + private final TrackerServer server; private int timeout; @@ -155,7 +158,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { message.append(" HEX: "); message.append(ByteBufUtil.hexDump((ByteBuf) networkMessage.getMessage())); - Log.debug(message.toString()); + LOGGER.debug(message.toString()); } } @@ -352,7 +355,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { try { pipeline.addLast("extraHandler." + i, (ChannelHandler) Class.forName(handlers[i]).newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 62ee99946..4e5df329c 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -95,8 +95,12 @@ public abstract class BaseProtocol implements Protocol { if (command.getType().equals(Command.TYPE_CUSTOM)) { Context.getSmsManager().sendMessageSync(destAddress, command.getString(Command.KEY_DATA), true); } else if (supportedTextCommands.contains(command.getType()) && textCommandEncoder != null) { - Context.getSmsManager().sendMessageSync(destAddress, - (String) textCommandEncoder.encodeCommand(command), true); + String encodedCommand = (String) textCommandEncoder.encodeCommand(command); + if (encodedCommand != null) { + Context.getSmsManager().sendMessageSync(destAddress, encodedCommand, true); + } else { + throw new RuntimeException("Failed to encode command"); + } } else { throw new RuntimeException( "Command " + command.getType() + " is not supported in protocol " + getName()); diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index d9ab60e3a..e940d96c4 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -17,7 +17,8 @@ package org.traccar; import io.netty.channel.Channel; import io.netty.channel.socket.DatagramChannel; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.helper.UnitsConverter; import org.traccar.model.Device; import org.traccar.model.Position; @@ -33,6 +34,8 @@ import java.sql.SQLException; public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(BaseProtocolDecoder.class); + private final Protocol protocol; public long addUnknownDevice(String uniqueId) { @@ -49,7 +52,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { try { Context.getDeviceManager().addItem(device); - Log.info("Automatically registered device " + uniqueId); + LOGGER.info("Automatically registered device " + uniqueId); if (defaultGroupId != 0) { Context.getPermissionsManager().refreshDeviceAndGroupPermissions(); @@ -58,7 +61,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { return device.getId(); } catch (SQLException e) { - Log.warning(e); + LOGGER.warn(null, e); return 0; } } @@ -107,7 +110,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { int timeZoneOffset = Context.getConfig().getInteger(getProtocolName() + ".timezone", 0); if (timeZoneOffset != 0) { result.setRawOffset(timeZoneOffset * 1000); - Log.warning("Config parameter " + getProtocolName() + ".timezone is deprecated"); + LOGGER.warn("Config parameter " + getProtocolName() + ".timezone is deprecated"); } } return result; @@ -131,7 +134,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } } } catch (Exception e) { - Log.warning(e); + LOGGER.warn(null, e); } if (deviceId == 0 && Context.getConfig().getBoolean("database.registerUnknown")) { return addUnknownDevice(uniqueIds[0]); @@ -151,7 +154,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { if (remoteAddress != null) { message.append(" (").append(((InetSocketAddress) remoteAddress).getHostString()).append(")"); } - Log.warning(message.toString()); + LOGGER.warn(message.toString()); } return 0; } diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java index ed71b5551..d7625e4b8 100644 --- a/src/org/traccar/BaseProtocolEncoder.java +++ b/src/org/traccar/BaseProtocolEncoder.java @@ -19,12 +19,15 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.Command; import org.traccar.model.Device; public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(BaseProtocolEncoder.class); + protected String getUniqueId(long deviceId) { return Context.getIdentityManager().getById(deviceId).getUniqueId(); } @@ -60,7 +63,7 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter } else { s.append("not sent"); } - Log.info(s.toString()); + LOGGER.info(s.toString()); ctx.write(new NetworkMessage(encodedCommand, networkMessage.getRemoteAddress()), promise); diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index d607baf3e..9a8bb97a9 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -27,6 +27,8 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; import org.apache.velocity.app.VelocityEngine; import org.eclipse.jetty.util.URIUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.database.CalendarManager; import org.traccar.database.CommandsManager; import org.traccar.database.AttributesManager; @@ -87,9 +89,17 @@ import javax.ws.rs.client.ClientBuilder; public final class Context { + private static final Logger LOGGER = LoggerFactory.getLogger(Context.class); + + public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private Context() { } + public static String getAppVersion() { + return Context.class.getPackage().getImplementationVersion(); + } + private static Config config; public static Config getConfig() { @@ -398,7 +408,7 @@ public final class Context { try { smsManager = (SmsManager) Class.forName(smsManagerClass).newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - Log.warning("Error loading SMS Manager class : " + smsManagerClass, e); + LOGGER.warn("Error loading SMS Manager class : " + smsManagerClass, e); } } diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java index 1ac3efc77..f62dca681 100644 --- a/src/org/traccar/DefaultDataHandler.java +++ b/src/org/traccar/DefaultDataHandler.java @@ -15,18 +15,21 @@ */ package org.traccar; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.Position; public class DefaultDataHandler extends BaseDataHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataHandler.class); + @Override protected Position handlePosition(Position position) { try { Context.getDataManager().addObject(position); } catch (Exception error) { - Log.warning(error); + LOGGER.warn(null, error); } return position; diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 7ad68f386..b127e190a 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -16,13 +16,16 @@ package org.traccar; import io.netty.channel.ChannelHandler; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @ChannelHandler.Sharable public class FilterHandler extends BaseDataHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(FilterHandler.class); + private boolean filterInvalid; private boolean filterZero; private boolean filterDuplicate; @@ -236,7 +239,7 @@ public class FilterHandler extends BaseDataHandler { message.append("filters from device: "); message.append(Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId()); - Log.info(message.toString()); + LOGGER.info(message.toString()); return true; } diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java index 0f3ba4731..72f164948 100644 --- a/src/org/traccar/GeocoderHandler.java +++ b/src/org/traccar/GeocoderHandler.java @@ -18,13 +18,16 @@ package org.traccar; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.geocoder.Geocoder; -import org.traccar.helper.Log; import org.traccar.model.Position; @ChannelHandler.Sharable public class GeocoderHandler extends ChannelInboundHandlerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(GeocoderHandler.class); + private final Geocoder geocoder; private final boolean processInvalidPositions; private final int geocoderReuseDistance; @@ -63,7 +66,7 @@ public class GeocoderHandler extends ChannelInboundHandlerAdapter { @Override public void onFailure(Throwable e) { - Log.warning("Geocoding failed", e); + LOGGER.warn("Geocoding failed", e); ctx.fireChannelRead(position); } }); diff --git a/src/org/traccar/GeolocationHandler.java b/src/org/traccar/GeolocationHandler.java index 0c204dc0b..27043e94e 100644 --- a/src/org/traccar/GeolocationHandler.java +++ b/src/org/traccar/GeolocationHandler.java @@ -18,13 +18,16 @@ package org.traccar; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.geolocation.GeolocationProvider; import org.traccar.model.Position; @ChannelHandler.Sharable public class GeolocationHandler extends ChannelInboundHandlerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(GeolocationHandler.class); + private final GeolocationProvider geolocationProvider; private final boolean processInvalidPositions; @@ -60,7 +63,7 @@ public class GeolocationHandler extends ChannelInboundHandlerAdapter { @Override public void onFailure(Throwable e) { - Log.warning(e); + LOGGER.warn(null, e); ctx.fireChannelRead(position); } }); diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java index 1e2db2693..fd1f07dca 100644 --- a/src/org/traccar/Main.java +++ b/src/org/traccar/Main.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,14 @@ */ package org.traccar; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.nio.charset.Charset; import java.sql.SQLException; import java.util.Timer; import java.util.TimerTask; @@ -24,16 +30,47 @@ import java.util.Locale; public final class Main { + private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); + private static final long CLEAN_PERIOD = 24 * 60 * 60 * 1000; private Main() { } + public static void logSystemInfo() { + try { + OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean(); + LOGGER.info("Operating system" + + " name: " + operatingSystemBean.getName() + + " version: " + operatingSystemBean.getVersion() + + " architecture: " + operatingSystemBean.getArch()); + + RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); + LOGGER.info("Java runtime" + + " name: " + runtimeBean.getVmName() + + " vendor: " + runtimeBean.getVmVendor() + + " version: " + runtimeBean.getVmVersion()); + + MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); + LOGGER.info("Memory limit" + + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb" + + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"); + + LOGGER.info("Character encoding: " + + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset()); + + } catch (Exception error) { + LOGGER.warn("Failed to get system info"); + } + } + public static void main(String[] args) throws Exception { Locale.setDefault(Locale.ENGLISH); Context.init(args); - Log.info("Starting server..."); + logSystemInfo(); + LOGGER.info("Version: " + Context.getAppVersion()); + LOGGER.info("Starting server..."); Context.getServerManager().start(); if (Context.getWebServer() != null) { @@ -46,7 +83,7 @@ public final class Main { try { Context.getDataManager().clearHistory(); } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }, 0, CLEAN_PERIOD); @@ -54,7 +91,7 @@ public final class Main { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - Log.info("Shutting down server..."); + LOGGER.info("Shutting down server..."); if (Context.getWebServer() != null) { Context.getWebServer().stop(); 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<String> 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()); } } diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index a8da6d57e..a67f71be2 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -15,7 +15,8 @@ */ package org.traccar; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.net.BindException; @@ -33,6 +34,8 @@ import java.util.jar.JarFile; public class ServerManager { + private static final Logger LOGGER = LoggerFactory.getLogger(ServerManager.class); + private final List<TrackerServer> serverList = new LinkedList<>(); private final Map<String, BaseProtocol> protocolList = new ConcurrentHashMap<>(); @@ -84,7 +87,7 @@ public class ServerManager { try { server.start(); } catch (BindException e) { - Log.warning("One of the protocols is disabled due to port conflict"); + LOGGER.warn("One of the protocols is disabled due to port conflict"); } } } diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index 65b272df4..a8b4ab94a 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -16,8 +16,9 @@ package org.traccar; import com.fasterxml.jackson.core.JsonProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Position; @@ -34,6 +35,8 @@ import java.util.TimeZone; public class WebDataHandler extends BaseDataHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(WebDataHandler.class); + private final String url; private final boolean json; private static final String KEY_POSITION = "position"; @@ -127,7 +130,7 @@ public class WebDataHandler extends BaseDataHandler { try { Context.getClient().target(formatRequest(position)).request().async().get(); } catch (UnsupportedEncodingException | JsonProcessingException e) { - Log.warning(e); + LOGGER.warn(null, e); } } return position; diff --git a/src/org/traccar/api/AsyncSocket.java b/src/org/traccar/api/AsyncSocket.java index 70523d253..783aeb740 100644 --- a/src/org/traccar/api/AsyncSocket.java +++ b/src/org/traccar/api/AsyncSocket.java @@ -18,9 +18,10 @@ package org.traccar.api; import com.fasterxml.jackson.core.JsonProcessingException; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.database.ConnectionManager; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -32,6 +33,8 @@ import java.util.Map; public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.UpdateListener { + private static final Logger LOGGER = LoggerFactory.getLogger(AsyncSocket.class); + private static final String KEY_DEVICES = "devices"; private static final String KEY_POSITIONS = "positions"; private static final String KEY_EVENTS = "events"; @@ -86,7 +89,7 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U try { getRemote().sendString(Context.getObjectMapper().writeValueAsString(data), null); } catch (JsonProcessingException e) { - Log.warning(e); + LOGGER.warn(null, e); } } } diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java index aace9f705..a76b34ad1 100644 --- a/src/org/traccar/api/SecurityRequestFilter.java +++ b/src/org/traccar/api/SecurityRequestFilter.java @@ -15,10 +15,11 @@ */ package org.traccar.api; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.api.resource.SessionResource; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.User; import javax.annotation.security.PermitAll; @@ -35,6 +36,8 @@ import java.sql.SQLException; public class SecurityRequestFilter implements ContainerRequestFilter { + private static final Logger LOGGER = LoggerFactory.getLogger(SecurityRequestFilter.class); + public static final String AUTHORIZATION_HEADER = "Authorization"; public static final String WWW_AUTHENTICATE = "WWW-Authenticate"; public static final String BASIC_REALM = "Basic realm=\"api\""; @@ -93,7 +96,7 @@ public class SecurityRequestFilter implements ContainerRequestFilter { } } catch (SecurityException e) { - Log.warning(e); + LOGGER.warn(null, e); } if (securityContext != null) { diff --git a/src/org/traccar/database/BaseObjectManager.java b/src/org/traccar/database/BaseObjectManager.java index cc1dbde5f..7a17f8934 100644 --- a/src/org/traccar/database/BaseObjectManager.java +++ b/src/org/traccar/database/BaseObjectManager.java @@ -24,11 +24,14 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.BaseModel; public class BaseObjectManager<T extends BaseModel> { + private static final Logger LOGGER = LoggerFactory.getLogger(BaseObjectManager.class); + private final DataManager dataManager; private Map<Long, T> items; @@ -74,7 +77,7 @@ public class BaseObjectManager<T extends BaseModel> { } } } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java index c11f05f9b..daf154dc4 100644 --- a/src/org/traccar/database/CommandsManager.java +++ b/src/org/traccar/database/CommandsManager.java @@ -26,15 +26,18 @@ import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocol; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Command; import org.traccar.model.Typed; import org.traccar.model.Position; public class CommandsManager extends ExtendedObjectManager<Command> { + private static final Logger LOGGER = LoggerFactory.getLogger(CommandsManager.class); + private final Map<Long, Queue<Command>> deviceQueues = new ConcurrentHashMap<>(); private boolean queueing; @@ -126,7 +129,7 @@ public class CommandsManager extends ExtendedObjectManager<Command> { try { result.add(new Typed(field.get(null).toString())); } catch (IllegalArgumentException | IllegalAccessException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index ef2085295..3918bcc5f 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -18,11 +18,12 @@ package org.traccar.database; import io.netty.channel.Channel; import io.netty.util.Timeout; import io.netty.util.TimerTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.GlobalTimer; import org.traccar.Protocol; import org.traccar.events.OverspeedEventHandler; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.DeviceState; import org.traccar.model.Event; @@ -40,6 +41,8 @@ import java.util.concurrent.TimeUnit; public class ConnectionManager { + private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionManager.class); + private static final long DEFAULT_TIMEOUT = 600; private final long deviceTimeout; @@ -130,7 +133,7 @@ public class ConnectionManager { try { Context.getDeviceManager().updateDeviceStatus(device); } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } updateDevice(device); diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 06dd26b17..71db329bc 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -39,9 +39,10 @@ import liquibase.exception.LiquibaseException; import liquibase.resource.FileSystemResourceAccessor; import liquibase.resource.ResourceAccessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Config; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Attribute; import org.traccar.model.Device; import org.traccar.model.Driver; @@ -65,6 +66,8 @@ import com.zaxxer.hikari.HikariDataSource; public class DataManager { + private static final Logger LOGGER = LoggerFactory.getLogger(DataManager.class); + public static final String ACTION_SELECT_ALL = "selectAll"; public static final String ACTION_SELECT = "select"; public static final String ACTION_INSERT = "insert"; @@ -209,7 +212,7 @@ public class DataManager { private String getQuery(String key) { String query = config.getString(key); if (query == null) { - Log.info("Query not provided: " + key); + LOGGER.info("Query not provided: " + key); } return query; } @@ -234,7 +237,7 @@ public class DataManager { query = constructObjectQuery(action, clazz, extended); config.setString(queryName, query); } else { - Log.info("Query not provided: " + queryName); + LOGGER.info("Query not provided: " + queryName); } } @@ -261,7 +264,7 @@ public class DataManager { property.equals(User.class) ? ManagedUser.class : property); config.setString(queryName, query); } else { - Log.info("Query not provided: " + queryName); + LOGGER.info("Query not provided: " + queryName); } } @@ -358,7 +361,8 @@ public class DataManager { long historyDays = config.getInteger("database.historyDays"); if (historyDays != 0) { Date timeLimit = new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000); - Log.debug("Clearing history earlier than " + new SimpleDateFormat(Log.DATE_FORMAT).format(timeLimit)); + LOGGER.debug( + "Clearing history earlier than " + new SimpleDateFormat(Context.DATE_FORMAT).format(timeLimit)); QueryBuilder.create(dataSource, getQuery("database.deletePositions")) .setDate("serverTime", timeLimit) .executeUpdate(); diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index bc8894743..be413a108 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -25,9 +25,10 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Config; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.DeviceState; import org.traccar.model.DeviceAccumulators; @@ -37,6 +38,8 @@ import org.traccar.model.Server; public class DeviceManager extends BaseObjectManager<Device> implements IdentityManager, ManagableObjects { + private static final Logger LOGGER = LoggerFactory.getLogger(DeviceManager.class); + public static final long DEFAULT_REFRESH_DELAY = 300; private final Config config; @@ -93,7 +96,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity try { updateDeviceCache(true); } catch (SQLException e) { - Log.warning(e); + LOGGER.warn(null, e); } result = super.getAllItems(); } @@ -228,7 +231,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity positions.put(position.getDeviceId(), position); } } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java index c9e349136..e48a3e802 100644 --- a/src/org/traccar/database/ExtendedObjectManager.java +++ b/src/org/traccar/database/ExtendedObjectManager.java @@ -23,8 +23,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.model.Permission; @@ -32,6 +33,8 @@ import org.traccar.model.BaseModel; public abstract class ExtendedObjectManager<T extends BaseModel> extends SimpleObjectManager<T> { + private static final Logger LOGGER = LoggerFactory.getLogger(ExtendedObjectManager.class); + private final Map<Long, Set<Long>> deviceItems = new ConcurrentHashMap<>(); private final Map<Long, Set<Long>> deviceItemsWithGroups = new ConcurrentHashMap<>(); private final Map<Long, Set<Long>> groupItems = new ConcurrentHashMap<>(); @@ -105,7 +108,7 @@ public abstract class ExtendedObjectManager<T extends BaseModel> extends SimpleO } } catch (SQLException | ClassNotFoundException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/GroupsManager.java b/src/org/traccar/database/GroupsManager.java index 262f15519..eca39f972 100644 --- a/src/org/traccar/database/GroupsManager.java +++ b/src/org/traccar/database/GroupsManager.java @@ -21,12 +21,15 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Group; public class GroupsManager extends BaseObjectManager<Group> implements ManagableObjects { + private static final Logger LOGGER = LoggerFactory.getLogger(GroupsManager.class); + private AtomicLong groupsLastUpdate = new AtomicLong(); private final long dataRefreshDelay; @@ -62,7 +65,7 @@ public class GroupsManager extends BaseObjectManager<Group> implements Managable try { updateGroupCache(true); } catch (SQLException e) { - Log.warning(e); + LOGGER.warn(null, e); } result = super.getAllItems(); } diff --git a/src/org/traccar/database/LdapProvider.java b/src/org/traccar/database/LdapProvider.java index eb975ad0f..612abe055 100644 --- a/src/org/traccar/database/LdapProvider.java +++ b/src/org/traccar/database/LdapProvider.java @@ -23,14 +23,17 @@ import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Config; -import org.traccar.helper.Log; import org.traccar.model.User; import java.util.Hashtable; public class LdapProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(LdapProvider.class); + private String url; private String searchBase; private String idAttribute; @@ -85,7 +88,7 @@ public class LdapProvider { if (results.hasMoreElements()) { results.nextElement(); if (results.hasMoreElements()) { - Log.warning("Matched multiple users for the accountName: " + accountName); + LOGGER.warn("Matched multiple users for the accountName: " + accountName); return false; } return true; @@ -117,7 +120,7 @@ public class LdapProvider { if (results.hasMoreElements()) { searchResult = results.nextElement(); if (results.hasMoreElements()) { - Log.warning("Matched multiple users for the accountName: " + accountName); + LOGGER.warn("Matched multiple users for the accountName: " + accountName); return null; } } @@ -155,7 +158,7 @@ public class LdapProvider { user.setLogin(accountName); user.setName(accountName); user.setEmail(accountName); - Log.warning(e); + LOGGER.warn(null, e); } return user; } diff --git a/src/org/traccar/database/MediaManager.java b/src/org/traccar/database/MediaManager.java index eb23d162f..62459cb5e 100644 --- a/src/org/traccar/database/MediaManager.java +++ b/src/org/traccar/database/MediaManager.java @@ -16,7 +16,8 @@ package org.traccar.database; import io.netty.buffer.ByteBuf; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileOutputStream; @@ -31,6 +32,8 @@ import java.util.Date; public class MediaManager { + private static final Logger LOGGER = LoggerFactory.getLogger(MediaManager.class); + private String path; public MediaManager(String path) { @@ -60,7 +63,7 @@ public class MediaManager { fileChannel.force(false); return name; } catch (IOException e) { - Log.warning(e); + LOGGER.warn(null, e); } } return null; diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 5dcb1d317..71a0a82e4 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -25,8 +25,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Calendar; import org.traccar.model.Event; import org.traccar.model.Notification; @@ -35,6 +36,8 @@ import org.traccar.model.Typed; public class NotificationManager extends ExtendedObjectManager<Notification> { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificationManager.class); + private boolean geocodeOnRequest; public NotificationManager(DataManager dataManager) { @@ -61,7 +64,7 @@ public class NotificationManager extends ExtendedObjectManager<Notification> { try { getDataManager().addObject(event); } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } if (position != null && geocodeOnRequest && Context.getGeocoder() != null && position.getAddress() == null) { @@ -114,7 +117,7 @@ public class NotificationManager extends ExtendedObjectManager<Notification> { try { types.add(new Typed(field.get(null).toString())); } catch (IllegalArgumentException | IllegalAccessException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index 1c19f2374..c9d548fd1 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -15,8 +15,9 @@ */ package org.traccar.database; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Attribute; import org.traccar.model.BaseModel; import org.traccar.model.Calendar; @@ -40,6 +41,8 @@ import java.util.Set; public class PermissionsManager { + private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsManager.class); + private final DataManager dataManager; private final UsersManager usersManager; @@ -108,7 +111,7 @@ public class PermissionsManager { try { server = dataManager.getServer(); } catch (SQLException error) { - Log.warning(error); + LOGGER.warn(null, error); } } @@ -143,7 +146,7 @@ public class PermissionsManager { } } catch (SQLException | ClassNotFoundException error) { - Log.warning(error); + LOGGER.warn(null, error); } deviceUsers.clear(); diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index af33458a8..8075223f2 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -16,8 +16,9 @@ package org.traccar.database; import com.fasterxml.jackson.core.JsonProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.MiscFormatter; import org.traccar.model.Permission; @@ -43,6 +44,8 @@ import java.util.Map; public final class QueryBuilder { + private static final Logger LOGGER = LoggerFactory.getLogger(QueryBuilder.class); + private final Map<String, List<Integer>> indexMap = new HashMap<>(); private Connection connection; private PreparedStatement statement; @@ -289,7 +292,7 @@ public final class QueryBuilder { } } } catch (IllegalAccessException | InvocationTargetException | JsonProcessingException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } @@ -321,7 +324,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getBoolean(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -332,7 +335,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getInt(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -343,7 +346,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getLong(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -354,7 +357,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getDouble(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -365,7 +368,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getString(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -379,7 +382,7 @@ public final class QueryBuilder { method.invoke(object, new Date(timestamp.getTime())); } } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -390,7 +393,7 @@ public final class QueryBuilder { try { method.invoke(object, resultSet.getBytes(name)); } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); @@ -403,7 +406,7 @@ public final class QueryBuilder { try { method.invoke(object, Context.getObjectMapper().readValue(value, parameterType)); } catch (InvocationTargetException | IllegalAccessException | IOException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 0b4d11378..bf790da29 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -22,8 +22,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.BaseModel; import org.traccar.model.Permission; import org.traccar.model.User; @@ -31,6 +32,8 @@ import org.traccar.model.User; public abstract class SimpleObjectManager<T extends BaseModel> extends BaseObjectManager<T> implements ManagableObjects { + private static final Logger LOGGER = LoggerFactory.getLogger(SimpleObjectManager.class); + private Map<Long, Set<Long>> userItems; protected SimpleObjectManager(DataManager dataManager, Class<T> baseClass) { @@ -77,7 +80,7 @@ public abstract class SimpleObjectManager<T extends BaseModel> extends BaseObjec getUserItems(permission.getOwnerId()).add(permission.getPropertyId()); } } catch (SQLException | ClassNotFoundException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index 452cdffa0..f6ede0a12 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -16,8 +16,9 @@ package org.traccar.database; import org.joda.time.format.ISODateTimeFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Statistics; import javax.ws.rs.client.Entity; @@ -31,6 +32,8 @@ import java.util.concurrent.atomic.AtomicInteger; public class StatisticsManager { + private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsManager.class); + private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH; private AtomicInteger lastUpdate = new AtomicInteger(Calendar.getInstance().get(SPLIT_MODE)); @@ -64,7 +67,7 @@ public class StatisticsManager { try { Context.getDataManager().addObject(statistics); } catch (SQLException e) { - Log.warning(e); + LOGGER.warn(null, e); } String url = Context.getConfig().getString("server.statistics"); @@ -72,7 +75,7 @@ public class StatisticsManager { String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime()); Form form = new Form(); - form.param("version", Log.getAppVersion()); + form.param("version", Context.getAppVersion()); form.param("captureTime", time); form.param("activeUsers", String.valueOf(statistics.getActiveUsers())); form.param("activeDevices", String.valueOf(statistics.getActiveDevices())); diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java index 36a3acb76..c0c789a51 100644 --- a/src/org/traccar/geocoder/JsonGeocoder.java +++ b/src/org/traccar/geocoder/JsonGeocoder.java @@ -15,8 +15,9 @@ */ package org.traccar.geocoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import javax.json.JsonObject; import javax.ws.rs.ClientErrorException; @@ -29,6 +30,8 @@ import java.util.Map; public abstract class JsonGeocoder implements Geocoder { + private static final Logger LOGGER = LoggerFactory.getLogger(JsonGeocoder.class); + private final String url; private final AddressFormat addressFormat; @@ -64,7 +67,7 @@ public abstract class JsonGeocoder implements Geocoder { if (callback != null) { callback.onFailure(new GeocoderException("Empty address")); } else { - Log.warning("Empty address"); + LOGGER.warn("Empty address"); } } return null; @@ -102,7 +105,7 @@ public abstract class JsonGeocoder implements Geocoder { try { return handleResponse(latitude, longitude, request.get(JsonObject.class), null); } catch (ClientErrorException e) { - Log.warning(e); + LOGGER.warn(null, e); } } return null; diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java index a22e4bde2..42cd07cef 100644 --- a/src/org/traccar/helper/Log.java +++ b/src/org/traccar/helper/Log.java @@ -15,126 +15,137 @@ */ package org.traccar.helper; -import org.apache.log4j.Appender; -import org.apache.log4j.DailyRollingFileAppender; -import org.apache.log4j.Layout; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.varia.NullAppender; import org.traccar.Config; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryMXBean; -import java.lang.management.OperatingSystemMXBean; -import java.lang.management.RuntimeMXBean; -import java.nio.charset.Charset; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.ConsoleHandler; +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; public final class Log { private Log() { } - public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; - - private static final String LOGGER_NAME = "traccar"; - private static final String STACK_PACKAGE = "org.traccar"; private static final int STACK_LIMIT = 3; - private static Logger logger = null; - - public static String getAppVersion() { - return Log.class.getPackage().getImplementationVersion(); - } + private static class RollingFileHandler extends Handler { - public static void setupLogger(Config config) throws IOException { + private String name; + private String suffix; + private Writer writer; - Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n"); + RollingFileHandler(String name) { + this.name = name; + } - Appender appender = new DailyRollingFileAppender( - layout, config.getString("logger.file"), "'.'yyyyMMdd"); + @Override + public synchronized void publish(LogRecord record) { + if (isLoggable(record)) { + try { + String suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis())); + if (writer != null && !suffix.equals(this.suffix)) { + writer.close(); + writer = null; + new File(name).renameTo(new File(name + "." + this.suffix)); + } + if (writer == null) { + this.suffix = suffix; + writer = new BufferedWriter(new FileWriter(name)); + } + writer.write(getFormatter().format(record)); + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } - LogManager.resetConfiguration(); - LogManager.getRootLogger().addAppender(new NullAppender()); + @Override + public void flush() { + if (writer != null) { + try { + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } - logger = Logger.getLogger(LOGGER_NAME); - logger.addAppender(appender); - logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL)); + @Override + public void close() throws SecurityException { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } - Log.logSystemInfo(); - Log.info("Version: " + getAppVersion()); } - public static Logger getLogger() { - if (logger == null) { - logger = Logger.getLogger(LOGGER_NAME); - logger.setLevel(Level.OFF); + public static class LogFormatter extends Formatter { + + private static String formatLevel(Level level) { + switch (level.getName()) { + case "FINEST": + return "TRACE"; + case "FINER": + case "FINE": + return "DEBUG"; + case "INFO": + return "INFO"; + case "WARNING": + return "WARN"; + case "SEVERE": + default: + return "ERROR"; + } } - return logger; - } - public static void logSystemInfo() { - try { - OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean(); - Log.info("Operating system" - + " name: " + operatingSystemBean.getName() - + " version: " + operatingSystemBean.getVersion() - + " architecture: " + operatingSystemBean.getArch()); - - RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); - Log.info("Java runtime" - + " name: " + runtimeBean.getVmName() - + " vendor: " + runtimeBean.getVmVendor() - + " version: " + runtimeBean.getVmVersion()); - - MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); - Log.info("Memory limit" - + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb" - + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"); - - Log.info("Character encoding: " - + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset()); - - } catch (Exception error) { - Log.warning("Failed to get system info"); - } - } + @Override + public String format(LogRecord record) { + StringBuilder message = new StringBuilder(record.getMessage()); - public static void error(String msg) { - getLogger().error(msg); - } + if (record.getThrown() != null) { + message.append(" - ").append(exceptionStack(record.getThrown())); + } - public static void warning(String msg) { - getLogger().warn(msg); - } + return String.format("%1$tF %1$tT %2$5s: %3$s%n", + new Date(record.getMillis()), formatLevel(record.getLevel()), message.toString()); + } - public static void warning(Throwable exception) { - warning(null, exception); } - public static void warning(String msg, Throwable exception) { - StringBuilder s = new StringBuilder(); - if (msg != null) { - s.append(msg); + public static void setupLogger(Config config) throws IOException { + + Logger rootLogger = Logger.getLogger(""); + for (Handler handler : rootLogger.getHandlers()) { + rootLogger.removeHandler(handler); } - if (exception != null) { - if (msg != null) { - s.append(" - "); - } - s.append(exceptionStack(exception)); + + Handler handler; + if (config.getBoolean("logger.console")) { + handler = new ConsoleHandler(); + } else { + handler = new RollingFileHandler(config.getString("logger.file")); } - getLogger().warn(s.toString()); - } - public static void info(String msg) { - getLogger().info(msg); - } + handler.setFormatter(new LogFormatter()); + handler.setLevel(Level.parse(config.getString("logger.level").toUpperCase())); - public static void debug(String msg) { - getLogger().debug(msg); + rootLogger.addHandler(handler); } public static String exceptionStack(Throwable exception) { diff --git a/src/org/traccar/helper/LogAction.java b/src/org/traccar/helper/LogAction.java index 2f575537d..db13337b8 100644 --- a/src/org/traccar/helper/LogAction.java +++ b/src/org/traccar/helper/LogAction.java @@ -18,10 +18,14 @@ package org.traccar.helper; import java.beans.Introspector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.BaseModel; public final class LogAction { + private static final Logger LOGGER = LoggerFactory.getLogger(LogAction.class); + private LogAction() { } @@ -71,26 +75,25 @@ public final class LogAction { } public static void resetDeviceAccumulators(long userId, long deviceId) { - log(String.format(PATTERN_DEVICE_ACCUMULATORS, userId, ACTION_DEVICE_ACCUMULATORS, deviceId)); + LOGGER.info(String.format( + PATTERN_DEVICE_ACCUMULATORS, userId, ACTION_DEVICE_ACCUMULATORS, deviceId)); } private static void logObjectAction(String action, long userId, Class<?> clazz, long objectId) { - log(String.format(PATTERN_OBJECT, userId, action, Introspector.decapitalize(clazz.getSimpleName()), objectId)); + LOGGER.info(String.format( + PATTERN_OBJECT, userId, action, Introspector.decapitalize(clazz.getSimpleName()), objectId)); } private static void logLinkAction(String action, long userId, Class<?> owner, long ownerId, Class<?> property, long propertyId) { - log(String.format(PATTERN_LINK, userId, action, + LOGGER.info(String.format( + PATTERN_LINK, userId, action, Introspector.decapitalize(owner.getSimpleName()), ownerId, Introspector.decapitalize(property.getSimpleName()), propertyId)); } private static void logLoginAction(String action, long userId) { - log(String.format(PATTERN_LOGIN, userId, action)); - } - - private static void log(String msg) { - Log.info(msg); + LOGGER.info(String.format(PATTERN_LOGIN, userId, action)); } } diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 1bbb166a6..53eeb0b24 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -15,6 +15,9 @@ */ package org.traccar.helper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.management.ManagementFactory; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -22,6 +25,8 @@ import java.util.regex.PatternSyntaxException; public final class PatternUtil { + private static final Logger LOGGER = LoggerFactory.getLogger(PatternUtil.class); + private PatternUtil() { } @@ -66,7 +71,7 @@ public final class PatternUtil { result.stringTail = input.substring(matcher.group(1).length()); } } catch (PatternSyntaxException error) { - Log.warning(error); + LOGGER.warn(null, error); } } diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java index c6161397b..66aa7ee75 100644 --- a/src/org/traccar/model/Server.java +++ b/src/org/traccar/model/Server.java @@ -15,14 +15,14 @@ */ package org.traccar.model; +import org.traccar.Context; import org.traccar.database.QueryIgnore; -import org.traccar.helper.Log; public class Server extends ExtendedModel { @QueryIgnore public String getVersion() { - return Log.getAppVersion(); + return Context.getAppVersion(); } public void setVersion(String version) { diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java index c011403c5..57be29b31 100644 --- a/src/org/traccar/notification/NotificationFormatter.java +++ b/src/org/traccar/notification/NotificationFormatter.java @@ -26,8 +26,9 @@ import org.apache.velocity.VelocityContext; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.tools.generic.DateTool; import org.apache.velocity.tools.generic.NumberTool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -36,6 +37,8 @@ import org.traccar.reports.ReportUtils; public final class NotificationFormatter { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificationFormatter.class); + private NotificationFormatter() { } @@ -81,7 +84,7 @@ public final class NotificationFormatter { templateFilePath = Paths.get(path, event.getType() + ".vm").toString(); template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name()); } catch (ResourceNotFoundException error) { - Log.warning(error); + LOGGER.warn(null, error); templateFilePath = Paths.get(path, "unknown.vm").toString(); template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name()); } diff --git a/src/org/traccar/notification/NotificatorManager.java b/src/org/traccar/notification/NotificatorManager.java index a3b13ef25..7e8a9dd0e 100644 --- a/src/org/traccar/notification/NotificatorManager.java +++ b/src/org/traccar/notification/NotificatorManager.java @@ -21,14 +21,17 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Typed; import org.traccar.notificators.NotificatorNull; import org.traccar.notificators.Notificator; public final class NotificatorManager { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorManager.class); + private static final String DEFAULT_WEB_NOTIFICATOR = "org.traccar.notificators.NotificatorWeb"; private static final String DEFAULT_MAIL_NOTIFICATOR = "org.traccar.notificators.NotificatorMail"; private static final String DEFAULT_SMS_NOTIFICATOR = "org.traccar.notificators.NotificatorSms"; @@ -58,7 +61,7 @@ public final class NotificatorManager { try { notificators.put(type, (Notificator) Class.forName(className).newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - Log.error("Unable to load notificator class for " + type + " " + className + " " + e.getMessage()); + LOGGER.warn("Unable to load notificator class for " + type + " " + className + " " + e.getMessage()); } } } @@ -66,7 +69,7 @@ public final class NotificatorManager { public Notificator getNotificator(String type) { final Notificator notificator = notificators.get(type); if (notificator == null) { - Log.error("No notificator configured for type : " + type); + LOGGER.warn("No notificator configured for type : " + type); return NULL_NOTIFICATOR; } return notificator; diff --git a/src/org/traccar/notificators/Notificator.java b/src/org/traccar/notificators/Notificator.java index de9817c9f..c3fad1607 100644 --- a/src/org/traccar/notificators/Notificator.java +++ b/src/org/traccar/notificators/Notificator.java @@ -16,20 +16,23 @@ */ package org.traccar.notificators; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.notification.MessageException; public abstract class Notificator { + private static final Logger LOGGER = LoggerFactory.getLogger(Notificator.class); + public void sendAsync(final long userId, final Event event, final Position position) { new Thread(new Runnable() { public void run() { try { sendSync(userId, event, position); } catch (MessageException | InterruptedException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }).start(); diff --git a/src/org/traccar/notificators/NotificatorMail.java b/src/org/traccar/notificators/NotificatorMail.java index cf786ffc4..7aa1a2968 100644 --- a/src/org/traccar/notificators/NotificatorMail.java +++ b/src/org/traccar/notificators/NotificatorMail.java @@ -26,8 +26,9 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Date; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; @@ -38,6 +39,8 @@ import org.traccar.notification.PropertiesProvider; public final class NotificatorMail extends Notificator { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorMail.class); + private static Properties getProperties(PropertiesProvider provider) { Properties properties = new Properties(); String host = provider.getString("mail.smtp.host"); @@ -97,7 +100,7 @@ public final class NotificatorMail extends Notificator { properties = getProperties(new PropertiesProvider(Context.getConfig())); } if (!properties.containsKey("mail.smtp.host")) { - Log.warning("No SMTP configuration found"); + LOGGER.warn("No SMTP configuration found"); return; } diff --git a/src/org/traccar/notificators/NotificatorNull.java b/src/org/traccar/notificators/NotificatorNull.java index 2120cda0c..9364336be 100644 --- a/src/org/traccar/notificators/NotificatorNull.java +++ b/src/org/traccar/notificators/NotificatorNull.java @@ -16,19 +16,23 @@ */ package org.traccar.notificators; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.model.Event; import org.traccar.model.Position; public final class NotificatorNull extends Notificator { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorNull.class); + @Override public void sendAsync(long userId, Event event, Position position) { - Log.warning("You are using null notificatior, please check your configuration, notification not sent"); + LOGGER.warn("You are using null notificatior, please check your configuration, notification not sent"); } @Override public void sendSync(long userId, Event event, Position position) { - Log.warning("You are using null notificatior, please check your configuration, notification not sent"); + LOGGER.warn("You are using null notificatior, please check your configuration, notification not sent"); } + } diff --git a/src/org/traccar/processing/ComputedAttributesHandler.java b/src/org/traccar/processing/ComputedAttributesHandler.java index a4edcc460..d4090e709 100644 --- a/src/org/traccar/processing/ComputedAttributesHandler.java +++ b/src/org/traccar/processing/ComputedAttributesHandler.java @@ -29,9 +29,10 @@ import io.netty.channel.ChannelHandler; import org.apache.commons.jexl2.JexlEngine; import org.apache.commons.jexl2.JexlException; import org.apache.commons.jexl2.MapContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseDataHandler; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Attribute; import org.traccar.model.Device; import org.traccar.model.Position; @@ -39,6 +40,8 @@ import org.traccar.model.Position; @ChannelHandler.Sharable public class ComputedAttributesHandler extends BaseDataHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(ComputedAttributesHandler.class); + private JexlEngine engine; private boolean mapDeviceAttributes; @@ -77,7 +80,7 @@ public class ComputedAttributesHandler extends BaseDataHandler { } } } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } @@ -98,7 +101,7 @@ public class ComputedAttributesHandler extends BaseDataHandler { try { result = computeAttribute(attribute, position); } catch (JexlException error) { - Log.warning(error); + LOGGER.warn(null, error); } if (result != null) { try { @@ -115,7 +118,7 @@ public class ComputedAttributesHandler extends BaseDataHandler { position.getAttributes().put(attribute.getAttribute(), result.toString()); } } catch (ClassCastException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/protocol/AdmProtocolEncoder.java b/src/org/traccar/protocol/AdmProtocolEncoder.java index bcbf8a2f1..e76bc2ddc 100644 --- a/src/org/traccar/protocol/AdmProtocolEncoder.java +++ b/src/org/traccar/protocol/AdmProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class AdmProtocolEncoder extends StringProtocolEncoder { @@ -33,11 +32,8 @@ public class AdmProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, "{%s}\r\n", Command.KEY_DATA); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index bfd92e0ad..bb821893a 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -18,11 +18,12 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -33,6 +34,8 @@ import java.util.Date; public class AplicomProtocolDecoder extends BaseProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(AplicomProtocolDecoder.class); + public AplicomProtocolDecoder(AplicomProtocol protocol) { super(protocol); } @@ -195,7 +198,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } break; default: - Log.warning(new UnsupportedOperationException()); + LOGGER.warn(null, new UnsupportedOperationException()); break; } } diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java index c386c7757..7c6a8fc1e 100644 --- a/src/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/org/traccar/protocol/AstraProtocolDecoder.java @@ -18,12 +18,13 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; -import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -34,6 +35,8 @@ import java.util.List; public class AstraProtocolDecoder extends BaseProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(AstraProtocolDecoder.class); + public AstraProtocolDecoder(AstraProtocol protocol) { super(protocol); } @@ -111,7 +114,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(status, 6)) { - Log.warning("Extension data is not supported"); + LOGGER.warn("Extension data is not supported"); return position; } diff --git a/src/org/traccar/protocol/AtrackProtocolEncoder.java b/src/org/traccar/protocol/AtrackProtocolEncoder.java index 1aa580435..1e085cb26 100644 --- a/src/org/traccar/protocol/AtrackProtocolEncoder.java +++ b/src/org/traccar/protocol/AtrackProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -32,11 +31,8 @@ public class AtrackProtocolEncoder extends BaseProtocolEncoder { return Unpooled.copiedBuffer( command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/CarcellProtocolEncoder.java b/src/org/traccar/protocol/CarcellProtocolEncoder.java index 0846949c4..e8f0081a0 100644 --- a/src/org/traccar/protocol/CarcellProtocolEncoder.java +++ b/src/org/traccar/protocol/CarcellProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class CarcellProtocolEncoder extends StringProtocolEncoder { @@ -30,11 +29,8 @@ public class CarcellProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "$SRVCMD,{%s},BD#\r\n", Command.KEY_UNIQUE_ID); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/CastelProtocolEncoder.java b/src/org/traccar/protocol/CastelProtocolEncoder.java index dde8ac11f..e1f78e7c1 100644 --- a/src/org/traccar/protocol/CastelProtocolEncoder.java +++ b/src/org/traccar/protocol/CastelProtocolEncoder.java @@ -20,7 +20,6 @@ import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.Context; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -28,6 +27,7 @@ import java.nio.charset.StandardCharsets; public class CastelProtocolEncoder extends BaseProtocolEncoder { private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) { + ByteBuf buf = Unpooled.buffer(0); String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId(); @@ -63,10 +63,8 @@ public class CastelProtocolEncoder extends BaseProtocolEncoder { content.writeByte(0); return encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - return null; } } diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java index 986dc75ec..9bf9601fe 100644 --- a/src/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java @@ -18,11 +18,14 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseFrameDecoder; -import org.traccar.helper.Log; public class CellocatorFrameDecoder extends BaseFrameDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(CellocatorFrameDecoder.class); + private static final int MESSAGE_MINIMUM_LENGTH = 15; @Override @@ -54,7 +57,6 @@ public class CellocatorFrameDecoder extends BaseFrameDecoder { length = 15 + buf.getUnsignedByte(13); break; default: - Log.warning(new UnsupportedOperationException(String.valueOf(type))); break; } diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java index 4eef42128..0382dbbc7 100644 --- a/src/org/traccar/protocol/CellocatorProtocolEncoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class CellocatorProtocolEncoder extends BaseProtocolEncoder { @@ -60,11 +59,8 @@ public class CellocatorProtocolEncoder extends BaseProtocolEncoder { + command.getInteger(Command.KEY_INDEX); return encodeContent(command.getDeviceId(), 0x03, data, 0); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java index e143563f0..350fdf0ab 100644 --- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java @@ -21,7 +21,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; public class CityeasyProtocolEncoder extends BaseProtocolEncoder { @@ -67,11 +66,8 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { content.writeShort(Math.abs(timezone)); return encodeContent(CityeasyProtocolDecoder.MSG_TIMEZONE, content); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java index 64236ca4a..c3ff88e1e 100644 --- a/src/org/traccar/protocol/EelinkProtocolEncoder.java +++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java @@ -17,9 +17,10 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.ByteBuffer; @@ -27,6 +28,8 @@ import java.nio.charset.StandardCharsets; public class EelinkProtocolEncoder extends BaseProtocolEncoder { + private static final Logger LOGGER = LoggerFactory.getLogger(EelinkProtocolEncoder.class); + private boolean connectionless; public EelinkProtocolEncoder(boolean connectionless) { @@ -100,11 +103,8 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_REBOOT_DEVICE: return encodeContent(command.getDeviceId(), "RESET#"); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/EnforaProtocolEncoder.java b/src/org/traccar/protocol/EnforaProtocolEncoder.java index a8fe53691..a46e6367d 100644 --- a/src/org/traccar/protocol/EnforaProtocolEncoder.java +++ b/src/org/traccar/protocol/EnforaProtocolEncoder.java @@ -19,7 +19,6 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -49,11 +48,8 @@ public class EnforaProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return encodeContent("AT$IOGP3=0"); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/EsealProtocolEncoder.java b/src/org/traccar/protocol/EsealProtocolEncoder.java index 886bb80b1..b9bcc5b0a 100644 --- a/src/org/traccar/protocol/EsealProtocolEncoder.java +++ b/src/org/traccar/protocol/EsealProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class EsealProtocolEncoder extends StringProtocolEncoder { @@ -35,11 +34,8 @@ public class EsealProtocolEncoder extends StringProtocolEncoder { return formatCommand( command, "##S,eSeal,{%s},256,3.0.8,RC-Unlock,E##", Command.KEY_UNIQUE_ID); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/GalileoProtocolEncoder.java b/src/org/traccar/protocol/GalileoProtocolEncoder.java index 12463dc7d..3b2145e74 100644 --- a/src/org/traccar/protocol/GalileoProtocolEncoder.java +++ b/src/org/traccar/protocol/GalileoProtocolEncoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -61,11 +60,8 @@ public class GalileoProtocolEncoder extends BaseProtocolEncoder { return encodeText(getUniqueId(command.getDeviceId()), "Out " + command.getInteger(Command.KEY_INDEX) + "," + command.getString(Command.KEY_DATA)); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/Gl200ProtocolEncoder.java b/src/org/traccar/protocol/Gl200ProtocolEncoder.java index 2c8efa318..285106c67 100644 --- a/src/org/traccar/protocol/Gl200ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class Gl200ProtocolEncoder extends StringProtocolEncoder { @@ -40,11 +39,8 @@ public class Gl200ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_REBOOT_DEVICE: return formatCommand(command, "AT+GTRTO={%s},3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java index 36801b401..47ef2f333 100644 --- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class Gps103ProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter { @@ -62,11 +61,8 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri case Command.TYPE_REQUEST_PHOTO: return formatCommand(command, "**,imei:{%s},160", Command.KEY_UNIQUE_ID); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java index bde267ee6..6345ff971 100644 --- a/src/org/traccar/protocol/GranitProtocolEncoder.java +++ b/src/org/traccar/protocol/GranitProtocolEncoder.java @@ -20,36 +20,29 @@ import java.nio.charset.StandardCharsets; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class GranitProtocolEncoder extends BaseProtocolEncoder { - @Override - protected Object encodeCommand(Command command) { - String commandString = ""; + private ByteBuf encodeCommand(String commandString) { + ByteBuf buffer = Unpooled.buffer(); + buffer.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII)); + GranitProtocolDecoder.appendChecksum(buffer, commandString.length()); + return buffer; + } + @Override + protected Object encodeCommand(Command command) { switch (command.getType()) { case Command.TYPE_IDENTIFICATION: - commandString = "BB+IDNT"; - break; + return encodeCommand("BB+IDNT"); case Command.TYPE_REBOOT_DEVICE: - commandString = "BB+RESET"; - break; + return encodeCommand("BB+RESET"); case Command.TYPE_POSITION_SINGLE: - commandString = "BB+RRCD"; - break; + return encodeCommand("BB+RRCD"); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } - if (!commandString.isEmpty()) { - ByteBuf commandBuf = Unpooled.buffer(); - commandBuf.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII)); - GranitProtocolDecoder.appendChecksum(commandBuf, commandString.length()); - return commandBuf; - } - return null; } } diff --git a/src/org/traccar/protocol/GranitProtocolSmsEncoder.java b/src/org/traccar/protocol/GranitProtocolSmsEncoder.java index 668e5d4d3..7d5518c17 100644 --- a/src/org/traccar/protocol/GranitProtocolSmsEncoder.java +++ b/src/org/traccar/protocol/GranitProtocolSmsEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class GranitProtocolSmsEncoder extends StringProtocolEncoder { @@ -30,7 +29,6 @@ public class GranitProtocolSmsEncoder extends StringProtocolEncoder { case Command.TYPE_POSITION_PERIODIC: return formatCommand(command, "BB+BBMD={%s}", Command.KEY_FREQUENCY); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index 46b4fa5a4..05560229f 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -20,7 +20,6 @@ import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.Context; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -72,11 +71,8 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_CUSTOM: return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/H02ProtocolEncoder.java b/src/org/traccar/protocol/H02ProtocolEncoder.java index fb418dbab..87fad6016 100644 --- a/src/org/traccar/protocol/H02ProtocolEncoder.java +++ b/src/org/traccar/protocol/H02ProtocolEncoder.java @@ -19,7 +19,6 @@ package org.traccar.protocol; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class H02ProtocolEncoder extends StringProtocolEncoder { @@ -57,11 +56,8 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { return formatCommand( time, uniqueId, "S71", "22", command.getAttributes().get(Command.KEY_FREQUENCY).toString()); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } @Override diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java index a2702fec7..056597b50 100644 --- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolEncoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.text.SimpleDateFormat; @@ -46,7 +45,6 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder { data.writeBytes(time); return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } finally { diff --git a/src/org/traccar/protocol/Jt600ProtocolEncoder.java b/src/org/traccar/protocol/Jt600ProtocolEncoder.java index 1d868cbcf..fe5c63c32 100644 --- a/src/org/traccar/protocol/Jt600ProtocolEncoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import java.util.TimeZone; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class Jt600ProtocolEncoder extends StringProtocolEncoder { @@ -37,11 +36,8 @@ public class Jt600ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_REBOOT_DEVICE: return "(S17)"; default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java index 9c0f0b67a..c66129283 100644 --- a/src/org/traccar/protocol/KhdProtocolEncoder.java +++ b/src/org/traccar/protocol/KhdProtocolEncoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; public class KhdProtocolEncoder extends BaseProtocolEncoder { @@ -61,11 +60,8 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return encodeCommand(MSG_RESUME_OIL, uniqueId); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java index 6052b2617..57cbbe0fc 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java @@ -20,7 +20,6 @@ import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -80,11 +79,8 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_REBOOT_DEVICE: return encodeContent(command.getDeviceId(), MeiligaoProtocolDecoder.MSG_REBOOT_GPS, content); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java index af059508b..abb6ec9d4 100644 --- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.traccar.Context; import org.traccar.StringProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.util.Map; @@ -59,11 +58,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, 'f', "C02,0," + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE)); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java index d3f49b4e4..7a3d5b226 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import java.util.TimeZone; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter { @@ -76,7 +75,6 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements case Command.TYPE_SET_INDICATOR: return formatCommand(command, "{%s}LED{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 94b624612..ec20658c7 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -23,13 +23,14 @@ import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; -import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -41,6 +42,8 @@ import java.util.List; public class Mta6ProtocolDecoder extends BaseProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(Mta6ProtocolDecoder.class); + private final boolean simple; public Mta6ProtocolDecoder(Protocol protocol, boolean simple) { @@ -85,7 +88,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2); break; default: - Log.warning(new IllegalArgumentException()); + LOGGER.warn(null, new IllegalArgumentException()); break; } return Float.intBitsToFloat(previousFloat); @@ -192,7 +195,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } } catch (IndexOutOfBoundsException error) { - Log.warning(error); + LOGGER.warn(null, error); } return positions; diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index 19eb37c27..c330907f7 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -22,7 +22,6 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -301,11 +300,8 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { case MSG_TRACKING_DATA: return parseTrackingData(deviceSession, buf, sequenceNumber, timestamp); default: - Log.warning(new UnsupportedOperationException(String.valueOf(messageId))); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java index 53b0c54ba..92826c8b2 100644 --- a/src/org/traccar/protocol/NoranProtocolEncoder.java +++ b/src/org/traccar/protocol/NoranProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -58,11 +57,8 @@ public class NoranProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return encodeContent("*KW,000,007,000000,1#"); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/PretraceProtocolEncoder.java b/src/org/traccar/protocol/PretraceProtocolEncoder.java index e8e2f66c7..9cf951e3b 100644 --- a/src/org/traccar/protocol/PretraceProtocolEncoder.java +++ b/src/org/traccar/protocol/PretraceProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.traccar.BaseProtocolEncoder; import org.traccar.Context; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; public class PretraceProtocolEncoder extends BaseProtocolEncoder { @@ -40,7 +39,6 @@ public class PretraceProtocolEncoder extends BaseProtocolEncoder { return formatCommand( uniqueId, String.format("D221%1$d,%1$d,,", command.getInteger(Command.KEY_FREQUENCY))); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } diff --git a/src/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/org/traccar/protocol/Pt502ProtocolEncoder.java index bd56e306a..ed18208cc 100644 --- a/src/org/traccar/protocol/Pt502ProtocolEncoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import java.util.TimeZone; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class Pt502ProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter { @@ -52,11 +51,8 @@ public class Pt502ProtocolEncoder extends StringProtocolEncoder implements Strin case Command.TYPE_REQUEST_PHOTO: return formatCommand(command, "#PHO\r\n"); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java index 28aa65273..4242584c9 100644 --- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -67,11 +66,8 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder { content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA))); return encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 054171914..826311052 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -17,12 +17,13 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; -import org.traccar.helper.Log; import org.traccar.model.Position; import java.net.SocketAddress; @@ -30,6 +31,8 @@ import java.nio.charset.StandardCharsets; public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(SkypatrolProtocolDecoder.class); + private final long defaultMask; public SkypatrolProtocolDecoder(SkypatrolProtocol protocol) { @@ -81,7 +84,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { id = buf.toString(buf.readerIndex(), 22, StandardCharsets.US_ASCII).trim(); buf.skipBytes(22); } else { - Log.warning("No device id field"); + LOGGER.warn("No device id field"); return null; } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); diff --git a/src/org/traccar/protocol/SuntechProtocolEncoder.java b/src/org/traccar/protocol/SuntechProtocolEncoder.java index 5b1c802fa..90fa4aa39 100644 --- a/src/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/org/traccar/protocol/SuntechProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class SuntechProtocolEncoder extends StringProtocolEncoder { @@ -48,11 +47,8 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ALARM_DISARM: return formatCommand(command, "SA200CMD;{%s};02;Disable2\r", Command.KEY_UNIQUE_ID); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/SviasProtocolEncoder.java b/src/org/traccar/protocol/SviasProtocolEncoder.java index c26ee2032..9fce57223 100644 --- a/src/org/traccar/protocol/SviasProtocolEncoder.java +++ b/src/org/traccar/protocol/SviasProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol;
import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
import org.traccar.model.Command;
public class SviasProtocolEncoder extends StringProtocolEncoder {
@@ -42,10 +41,8 @@ public class SviasProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ALARM_REMOVE:
return formatCommand(command, "AT+PNC=600*");
default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
+ return null;
}
- return null;
}
}
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java index ba17c9d75..1d0f3dabe 100644 --- a/src/org/traccar/protocol/T800xProtocolEncoder.java +++ b/src/org/traccar/protocol/T800xProtocolEncoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -53,11 +52,8 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_CUSTOM: return encodeContent(command, command.getString(Command.KEY_DATA)); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java index f2680c27c..944cec024 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; -import org.traccar.helper.Log; import org.traccar.model.Command; import io.netty.buffer.ByteBuf; @@ -53,11 +52,8 @@ public class TeltonikaProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_CUSTOM: return encodeContent(command.getString(Command.KEY_DATA)); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java index d64c85c2c..d4544707a 100644 --- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.traccar.Context; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class Tk103ProtocolEncoder extends StringProtocolEncoder { @@ -75,7 +74,6 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_SOS_NUMBER: return formatAlt(command, "*master*{%s}*{%s}*", Command.KEY_DEVICE_PASSWORD, Command.KEY_PHONE); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } else { @@ -102,7 +100,6 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_OUTPUT_CONTROL: return formatCommand(command, "({%s}AV00{%s})", Command.KEY_UNIQUE_ID, Command.KEY_DATA); default: - Log.warning(new UnsupportedOperationException(command.getType())); return null; } } diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java index ff41a7df3..b5049859d 100644 --- a/src/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/org/traccar/protocol/TotemProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class TotemProtocolEncoder extends StringProtocolEncoder { @@ -34,11 +33,8 @@ public class TotemProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "*{%s},025,C,0#", Command.KEY_DEVICE_PASSWORD); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index b2d35e702..482f2f0bf 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import io.netty.channel.Channel; import org.traccar.StringProtocolEncoder; import org.traccar.helper.DataConverter; -import org.traccar.helper.Log; import org.traccar.model.Command; import java.nio.charset.StandardCharsets; @@ -144,11 +143,8 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin case Command.TYPE_SET_INDICATOR: return formatCommand(channel, command, "FLOWER,{%s}", Command.KEY_DATA); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/WialonProtocolEncoder.java b/src/org/traccar/protocol/WialonProtocolEncoder.java index 9c60a1356..9ff1631eb 100644 --- a/src/org/traccar/protocol/WialonProtocolEncoder.java +++ b/src/org/traccar/protocol/WialonProtocolEncoder.java @@ -17,7 +17,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class WialonProtocolEncoder extends StringProtocolEncoder { @@ -34,9 +33,8 @@ public class WialonProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_OUTPUT_CONTROL: return formatCommand(command, "L{%s}={%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - return null; } + } diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java index 6258c1fe6..f9e8eeb9b 100644 --- a/src/org/traccar/protocol/WondexProtocolEncoder.java +++ b/src/org/traccar/protocol/WondexProtocolEncoder.java @@ -16,10 +16,10 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class WondexProtocolEncoder extends StringProtocolEncoder { + @Override protected Object encodeCommand(Command command) { @@ -39,11 +39,8 @@ public class WondexProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_GET_VERSION: return formatCommand(command, "$WP+VER={%s}", Command.KEY_DEVICE_PASSWORD); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/XexunProtocolEncoder.java b/src/org/traccar/protocol/XexunProtocolEncoder.java index cdf3ac6f7..515cfbbd0 100644 --- a/src/org/traccar/protocol/XexunProtocolEncoder.java +++ b/src/org/traccar/protocol/XexunProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class XexunProtocolEncoder extends StringProtocolEncoder { @@ -32,11 +31,8 @@ public class XexunProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "powercar{%s} 00", Command.KEY_DEVICE_PASSWORD); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/protocol/XirgoProtocolEncoder.java b/src/org/traccar/protocol/XirgoProtocolEncoder.java index fde531831..dd5e30cca 100644 --- a/src/org/traccar/protocol/XirgoProtocolEncoder.java +++ b/src/org/traccar/protocol/XirgoProtocolEncoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; -import org.traccar.helper.Log; import org.traccar.model.Command; public class XirgoProtocolEncoder extends StringProtocolEncoder { @@ -28,11 +27,8 @@ public class XirgoProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_OUTPUT_CONTROL: return String.format("+XT:7005,%d,1", command.getInteger(Command.KEY_DATA) + 1); default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + return null; } - - return null; } } diff --git a/src/org/traccar/smpp/ClientSmppSessionHandler.java b/src/org/traccar/smpp/ClientSmppSessionHandler.java index 3585f8376..37882c76a 100644 --- a/src/org/traccar/smpp/ClientSmppSessionHandler.java +++ b/src/org/traccar/smpp/ClientSmppSessionHandler.java @@ -16,8 +16,9 @@ */ package org.traccar.smpp; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.events.TextMessageEventHandler; -import org.traccar.helper.Log; import com.cloudhopper.commons.charset.CharsetUtil; import com.cloudhopper.smpp.SmppConstants; @@ -29,6 +30,8 @@ import com.cloudhopper.smpp.util.SmppUtil; public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(ClientSmppSessionHandler.class); + private SmppClient smppClient; public ClientSmppSessionHandler(SmppClient smppClient) { @@ -37,7 +40,7 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { @Override public void firePduRequestExpired(PduRequest pduRequest) { - Log.warning("PDU request expired: " + pduRequest); + LOGGER.warn("PDU request expired: " + pduRequest); } @Override @@ -48,7 +51,7 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { String sourceAddress = ((DeliverSm) request).getSourceAddress().getAddress(); String message = CharsetUtil.decode(((DeliverSm) request).getShortMessage(), smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding())); - Log.debug("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress); + LOGGER.debug("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress); boolean isDeliveryReceipt = false; if (smppClient.getDetectDlrByOpts()) { @@ -63,7 +66,7 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { } response = request.createResponse(); } catch (Throwable error) { - Log.warning(error); + LOGGER.warn(null, error); response = request.createResponse(); response.setResultMessage(error.getMessage()); response.setCommandStatus(SmppConstants.STATUS_UNKNOWNERR); @@ -73,7 +76,7 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { @Override public void fireChannelUnexpectedlyClosed() { - Log.warning("SMPP session channel unexpectedly closed"); + LOGGER.warn("SMPP session channel unexpectedly closed"); smppClient.scheduleReconnect(); } } diff --git a/src/org/traccar/smpp/EnquireLinkTask.java b/src/org/traccar/smpp/EnquireLinkTask.java index affb712b3..3072f975a 100644 --- a/src/org/traccar/smpp/EnquireLinkTask.java +++ b/src/org/traccar/smpp/EnquireLinkTask.java @@ -16,7 +16,8 @@ */ package org.traccar.smpp; -import org.traccar.helper.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.cloudhopper.smpp.SmppSession; import com.cloudhopper.smpp.pdu.EnquireLink; @@ -27,6 +28,8 @@ import com.cloudhopper.smpp.type.UnrecoverablePduException; public class EnquireLinkTask implements Runnable { + private static final Logger LOGGER = LoggerFactory.getLogger(EnquireLinkTask.class); + private SmppClient smppClient; private Integer enquireLinkTimeout; @@ -43,13 +46,13 @@ public class EnquireLinkTask implements Runnable { smppSession.enquireLink(new EnquireLink(), enquireLinkTimeout); } catch (SmppTimeoutException | SmppChannelException | RecoverablePduException | UnrecoverablePduException error) { - Log.warning("Enquire link failed, executing reconnect: ", error); + LOGGER.warn("Enquire link failed, executing reconnect: ", error); smppClient.scheduleReconnect(); } catch (InterruptedException error) { - Log.info("Enquire link interrupted, probably killed by reconnecting"); + LOGGER.info("Enquire link interrupted, probably killed by reconnecting"); } } else { - Log.warning("Enquire link running while session is not connected"); + LOGGER.warn("Enquire link running while session is not connected"); } } diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java index ddda4cb4f..d7e262c87 100644 --- a/src/org/traccar/smpp/SmppClient.java +++ b/src/org/traccar/smpp/SmppClient.java @@ -23,8 +23,9 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.notification.MessageException; import org.traccar.sms.SmsManager; @@ -46,6 +47,8 @@ import com.cloudhopper.smpp.type.UnrecoverablePduException; public class SmppClient implements SmsManager { + private static final Logger LOGGER = LoggerFactory.getLogger(SmppClient.class); + private SmppSessionConfiguration sessionConfig = new SmppSessionConfiguration(); private SmppSession smppSession; private DefaultSmppSessionHandler sessionHandler = new ClientSmppSessionHandler(this); @@ -168,10 +171,10 @@ public class SmppClient implements SmsManager { smppSession = clientBootstrap.bind(sessionConfig, sessionHandler); stopReconnectionkTask(); runEnquireLinkTask(); - Log.info("SMPP session connected"); + LOGGER.info("SMPP session connected"); } catch (SmppTimeoutException | SmppChannelException | UnrecoverablePduException | InterruptedException error) { - Log.warning("Unable to connect to SMPP server: ", error); + LOGGER.warn("Unable to connect to SMPP server: ", error); } } @@ -208,7 +211,7 @@ public class SmppClient implements SmsManager { private void destroySession() { if (smppSession != null) { - Log.debug("Cleaning up SMPP session... "); + LOGGER.debug("Cleaning up SMPP session... "); smppSession.destroy(); smppSession = null; } @@ -239,7 +242,7 @@ public class SmppClient implements SmsManager { submit.setDestAddress(new Address(destTon, destNpi, destAddress)); SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout); if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) { - Log.debug("SMS submitted, message id: " + submitResponce.getMessageId()); + LOGGER.debug("SMS submitted, message id: " + submitResponce.getMessageId()); } else { throw new IllegalStateException(submitResponce.getResultMessage()); } @@ -260,7 +263,7 @@ public class SmppClient implements SmsManager { try { sendMessageSync(destAddress, message, command); } catch (MessageException | InterruptedException | IllegalStateException error) { - Log.warning(error); + LOGGER.warn(null, error); } } }); diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java index 9b3d8d54b..dddd13b6d 100644 --- a/src/org/traccar/web/ConsoleServlet.java +++ b/src/org/traccar/web/ConsoleServlet.java @@ -17,8 +17,9 @@ package org.traccar.web; import org.h2.server.web.ConnectionInfo; import org.h2.server.web.WebServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -26,6 +27,8 @@ import java.lang.reflect.Method; public class ConsoleServlet extends WebServlet { + private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleServlet.class); + @Override public void init() { super.init(); @@ -51,7 +54,7 @@ public class ConsoleServlet extends WebServlet { method.invoke(server, true); } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - Log.warning(e); + LOGGER.warn(null, e); } } diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java index fa99f1b18..d5149b528 100644 --- a/src/org/traccar/web/CsvBuilder.java +++ b/src/org/traccar/web/CsvBuilder.java @@ -31,11 +31,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.helper.Log; public class CsvBuilder { + private static final Logger LOGGER = LoggerFactory.getLogger(CsvBuilder.class); + private static final String LINE_ENDING = "\r\n"; private static final String SEPARATOR = ";"; private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); @@ -103,12 +106,12 @@ public class CsvBuilder { builder.append(map); addSeparator(); } catch (JsonProcessingException e) { - Log.warning(e); + LOGGER.warn(null, e); } } } } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); + LOGGER.warn(null, error); } } } diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 13eebf34f..32c336164 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -32,6 +32,8 @@ import org.eclipse.jetty.webapp.WebAppContext; import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Config; import org.traccar.Context; import org.traccar.api.AsyncSocketServlet; @@ -41,7 +43,6 @@ import org.traccar.api.ObjectMapperProvider; import org.traccar.api.ResourceErrorHandler; import org.traccar.api.SecurityRequestFilter; import org.traccar.api.resource.ServerResource; -import org.traccar.helper.Log; import javax.naming.InitialContext; import javax.servlet.DispatcherType; @@ -56,6 +57,8 @@ import java.util.EnumSet; public class WebServer { + private static final Logger LOGGER = LoggerFactory.getLogger(WebServer.class); + private Server server; private final Config config; private final DataSource dataSource; @@ -150,7 +153,7 @@ public class WebServer { javax.naming.Context context = new InitialContext(); context.bind("java:/DefaultDS", dataSource); } catch (Exception error) { - Log.warning(error); + LOGGER.warn(null, error); } WebAppContext app = new WebAppContext(); @@ -196,7 +199,7 @@ public class WebServer { try { server.start(); } catch (Exception error) { - Log.warning(error); + LOGGER.warn(null, error); } } @@ -204,7 +207,7 @@ public class WebServer { try { server.stop(); } catch (Exception error) { - Log.warning(error); + LOGGER.warn(null, error); } } |