Replacing log4j with slf4j

This commit is contained in:
UnAfraid 2019-09-09 20:10:26 +03:00
parent 6f0247232f
commit ef1bd09a6a
11 changed files with 49 additions and 38 deletions

14
pom.xml
View File

@ -39,7 +39,7 @@
<mockitojupiter.version>3.0.0</mockitojupiter.version> <mockitojupiter.version>3.0.0</mockitojupiter.version>
<jacksonbase.version>2.9.9</jacksonbase.version> <jacksonbase.version>2.9.9</jacksonbase.version>
<jackson.version>2.9.9.1</jackson.version> <jackson.version>2.9.9.1</jackson.version>
<log4j.version>2.12.0</log4j.version> <slf4j.version>1.7.28</slf4j.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -78,9 +78,9 @@
<version>${jackson.version}</version> <version>${jackson.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>slf4j-api</artifactId>
<version>${log4j.version}</version> <version>${slf4j.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -108,9 +108,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>slf4j-api</artifactId>
<version>${log4j.version}</version> <version>${slf4j.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -78,6 +78,7 @@
<commonslang.version>3.9</commonslang.version> <commonslang.version>3.9</commonslang.version>
<mapdb.version>3.0.7</mapdb.version> <mapdb.version>3.0.7</mapdb.version>
<log4j.version>2.12.1</log4j.version>
</properties> </properties>
<dependencies> <dependencies>
@ -102,6 +103,16 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.abilitybots.api.db.DBContext; import org.telegram.abilitybots.api.db.DBContext;
import org.telegram.abilitybots.api.objects.Ability; import org.telegram.abilitybots.api.objects.Ability;
import org.telegram.abilitybots.api.objects.Locality; import org.telegram.abilitybots.api.objects.Locality;
@ -139,7 +139,7 @@ import static org.telegram.abilitybots.api.util.AbilityUtils.stripTag;
*/ */
@SuppressWarnings({"ConfusingArgumentToVarargsMethod", "UnusedReturnValue", "WeakerAccess", "unused", "ConstantConditions"}) @SuppressWarnings({"ConfusingArgumentToVarargsMethod", "UnusedReturnValue", "WeakerAccess", "unused", "ConstantConditions"})
public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension { public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension {
private static final Logger log = LogManager.getLogger(BaseAbilityBot.class); private static final Logger log = LoggerFactory.getLogger(BaseAbilityBot.class);
// DB objects // DB objects
public static final String ADMINS = "ADMINS"; public static final String ADMINS = "ADMINS";

View File

@ -3,12 +3,12 @@ package org.telegram.abilitybots.api.db;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mapdb.Atomic; import org.mapdb.Atomic;
import org.mapdb.DB; import org.mapdb.DB;
import org.mapdb.DBMaker; import org.mapdb.DBMaker;
import org.mapdb.Serializer; import org.mapdb.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.abilitybots.api.util.Pair; import org.telegram.abilitybots.api.util.Pair;
import java.io.IOException; import java.io.IOException;
@ -35,7 +35,7 @@ import static org.mapdb.Serializer.JAVA;
*/ */
@SuppressWarnings({"unchecked", "WeakerAccess"}) @SuppressWarnings({"unchecked", "WeakerAccess"})
public class MapDBContext implements DBContext { public class MapDBContext implements DBContext {
private static final Logger log = LogManager.getLogger(MapDBContext.class); private static final Logger log = LoggerFactory.getLogger(MapDBContext.class);
private final DB db; private final DB db;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;

View File

@ -2,8 +2,8 @@ package org.telegram.abilitybots.api.objects;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import java.util.Arrays; import java.util.Arrays;
@ -35,7 +35,7 @@ import static org.apache.commons.lang3.StringUtils.*;
* @author Abbas Abou Daya * @author Abbas Abou Daya
*/ */
public final class Ability { public final class Ability {
private static final Logger log = LogManager.getLogger(Ability.class); private static final Logger log = LoggerFactory.getLogger(Ability.class);
private final String name; private final String name;
private final String info; private final String info;

View File

@ -1,7 +1,7 @@
package org.telegram.abilitybots.api.sender; package org.telegram.abilitybots.api.sender;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Message;
@ -18,7 +18,7 @@ import java.util.Optional;
* @author Abbas Abou Daya * @author Abbas Abou Daya
*/ */
public class SilentSender { public class SilentSender {
private static final Logger log = LogManager.getLogger(SilentSender.class); private static final Logger log = LoggerFactory.getLogger(SilentSender.class);
private final MessageSender sender; private final MessageSender sender;

View File

@ -4,8 +4,8 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
@ -16,7 +16,7 @@ import java.util.Map;
* @version 1.0 * @version 1.0
*/ */
public class ApiContext { public class ApiContext {
private static final Logger log = LogManager.getLogger(ApiContext.class); private static final Logger log = LoggerFactory.getLogger(ApiContext.class);
private static final Object lock = new Object(); private static final Object lock = new Object();
private static Injector INJECTOR; private static Injector INJECTOR;

View File

@ -18,9 +18,9 @@
package org.telegram.telegrambots.meta.exceptions; package org.telegram.telegrambots.meta.exceptions;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.ResponseParameters; import org.telegram.telegrambots.meta.api.objects.ResponseParameters;
@ -33,7 +33,7 @@ import java.io.IOException;
* Exception thrown when something goes wrong in the api * Exception thrown when something goes wrong in the api
*/ */
public class TelegramApiRequestException extends TelegramApiException { public class TelegramApiRequestException extends TelegramApiException {
private static final Logger log = LogManager.getLogger(TelegramApiRequestException.class); private static final Logger log = LoggerFactory.getLogger(TelegramApiRequestException.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final String ERRORDESCRIPTIONFIELD = "description"; private static final String ERRORDESCRIPTIONFIELD = "description";
@ -56,7 +56,7 @@ public class TelegramApiRequestException extends TelegramApiException {
try { try {
parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class); parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class);
} catch (IOException e) { } catch (IOException e) {
log.fatal(e.getLocalizedMessage(), e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

View File

@ -1,7 +1,7 @@
package org.telegram.telegrambots.starter; package org.telegram.telegrambots.starter;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
@ -21,7 +21,7 @@ import static java.lang.String.format;
* Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi. * Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi.
*/ */
public class TelegramBotInitializer implements InitializingBean { public class TelegramBotInitializer implements InitializingBean {
private static final Logger log = LogManager.getLogger(TelegramBotInitializer.class); private static final Logger log = LoggerFactory.getLogger(TelegramBotInitializer.class);
private final TelegramBotsApi telegramBotsApi; private final TelegramBotsApi telegramBotsApi;
private final List<LongPollingBot> longPollingBots; private final List<LongPollingBot> longPollingBots;

View File

@ -11,9 +11,9 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.ApiConstants; import org.telegram.telegrambots.meta.ApiConstants;
import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
@ -40,7 +40,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
* Thread to request updates with active wait * Thread to request updates with active wait
*/ */
public class DefaultBotSession implements BotSession { public class DefaultBotSession implements BotSession {
private static final Logger log = LogManager.getLogger(DefaultBotSession.class); private static final Logger log = LoggerFactory.getLogger(DefaultBotSession.class);
private AtomicBoolean running = new AtomicBoolean(false); private AtomicBoolean running = new AtomicBoolean(false);
@ -207,7 +207,7 @@ public class DefaultBotSession implements BotSession {
log.debug(e.getLocalizedMessage(), e); log.debug(e.getLocalizedMessage(), e);
interrupt(); interrupt();
} catch (Exception global) { } catch (Exception global) {
log.fatal(global.getLocalizedMessage(), global); log.error(global.getLocalizedMessage(), global);
try { try {
synchronized (lock) { synchronized (lock) {
lock.wait(exponentialBackOff.nextBackOffMillis()); lock.wait(exponentialBackOff.nextBackOffMillis());
@ -263,7 +263,7 @@ public class DefaultBotSession implements BotSession {
} }
} }
} catch (SocketException | InvalidObjectException | TelegramApiRequestException e) { } catch (SocketException | InvalidObjectException | TelegramApiRequestException e) {
log.fatal(e.getLocalizedMessage(), e); log.error(e.getLocalizedMessage(), e);
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
log.info(e.getLocalizedMessage(), e); log.info(e.getLocalizedMessage(), e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -309,7 +309,7 @@ public class DefaultBotSession implements BotSession {
log.debug(e.getLocalizedMessage(), e); log.debug(e.getLocalizedMessage(), e);
interrupt(); interrupt();
} catch (Exception e) { } catch (Exception e) {
log.fatal(e.getLocalizedMessage(), e); log.error(e.getLocalizedMessage(), e);
} }
} }
log.debug("Handler thread has being closed"); log.debug("Handler thread has being closed");

View File

@ -1,7 +1,7 @@
package org.telegram.telegrambots.updatesreceivers; package org.telegram.telegrambots.updatesreceivers;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
@Path("callback") @Path("callback")
public class RestApi { public class RestApi {
private static final Logger log = LogManager.getLogger(RestApi.class); private static final Logger log = LoggerFactory.getLogger(RestApi.class);
private final ConcurrentHashMap<String, WebhookBot> callbacks = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, WebhookBot> callbacks = new ConcurrentHashMap<>();