From b10824bb5769c4abb93e3451673b88efdfb9d467 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 14 Sep 2018 14:33:49 +1200 Subject: Log using slf4j and java logging --- src/org/traccar/smpp/ClientSmppSessionHandler.java | 13 ++++++++----- src/org/traccar/smpp/EnquireLinkTask.java | 11 +++++++---- src/org/traccar/smpp/SmppClient.java | 15 +++++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src/org/traccar/smpp') 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); } } }); -- cgit v1.2.3