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/traccar/database | |
parent | e331573c0df7467fd36ae3eba3c259ed9b1d9253 (diff) | |
download | traccar-server-b10824bb5769c4abb93e3451673b88efdfb9d467.tar.gz traccar-server-b10824bb5769c4abb93e3451673b88efdfb9d467.tar.bz2 traccar-server-b10824bb5769c4abb93e3451673b88efdfb9d467.zip |
Log using slf4j and java logging
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/BaseObjectManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/CommandsManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 14 | ||||
-rw-r--r-- | src/org/traccar/database/DeviceManager.java | 9 | ||||
-rw-r--r-- | src/org/traccar/database/ExtendedObjectManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/GroupsManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/LdapProvider.java | 11 | ||||
-rw-r--r-- | src/org/traccar/database/MediaManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/NotificationManager.java | 9 | ||||
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 9 | ||||
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 23 | ||||
-rw-r--r-- | src/org/traccar/database/SimpleObjectManager.java | 7 | ||||
-rw-r--r-- | src/org/traccar/database/StatisticsManager.java | 9 |
14 files changed, 88 insertions, 45 deletions
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())); |