From 09221ab5695e99b2df1130ea923c39625ec85429 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Thu, 10 Nov 2016 04:50:07 +0700 Subject: using slf4j + logback for logging --- .../main/java/com/juick/components/s2s/Connection.java | 11 ++++++----- .../java/com/juick/components/s2s/ConnectionIn.java | 18 +++++++++--------- .../java/com/juick/components/s2s/ConnectionOut.java | 9 ++++----- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'juick-xmpp/src/main/java') diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java index 0c1f3d4d..700293df 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java @@ -1,6 +1,8 @@ package com.juick.components.s2s; import com.juick.components.XMPPServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -17,7 +19,6 @@ import java.nio.charset.Charset; import java.security.*; import java.security.cert.CertificateException; import java.util.UUID; -import java.util.logging.Logger; /** * @@ -25,7 +26,7 @@ import java.util.logging.Logger; */ public class Connection { - protected static final Logger logger = Logger.getLogger(Connection.class.getName()); + protected static final Logger logger = LoggerFactory.getLogger(Connection.class); public String streamID; public long tsCreated = 0; @@ -68,7 +69,7 @@ public class Connection { sc = SSLContext.getInstance("TLSv1.2"); sc.init(kmf.getKeyManagers(), trustAllCerts, new SecureRandom()); } catch (Exception e) { - logger.warning("tls unavailable"); + logger.warn("tls unavailable"); } } @@ -81,12 +82,12 @@ public class Connection { tag += " " + parser.getAttributeName(i) + "=\"" + parser.getAttributeValue(i) + "\""; } tag += ">...\n"; - logger.fine(tag); + logger.trace(tag); } public void sendStanza(String xml) throws IOException { if (streamID != null) { - logger.fine("OUT: " + xml + "\n"); + logger.trace("OUT: " + xml + "\n"); } writer.write(xml); writer.flush(); diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index 41336582..8cc61e26 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -6,6 +6,8 @@ import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.utils.XmlUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xmlpull.v1.XmlPullParser; import javax.net.ssl.SSLException; @@ -17,8 +19,6 @@ import java.net.SocketException; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -26,7 +26,7 @@ import java.util.logging.Logger; */ public class ConnectionIn extends Connection implements Runnable { - private static final Logger LOGGER = Logger.getLogger(ConnectionIn.class.getName()); + private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionIn.class); final public List from = new ArrayList<>(); public long tsRemoteData = 0; @@ -109,7 +109,7 @@ public class ConnectionIn extends Connection implements Runnable { LOGGER.info("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY VALID"); } else { sendStanza(""); - LOGGER.warning("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID"); + LOGGER.warn("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID"); } } else if (tag.equals("presence") && checkFromTo(parser)) { Presence p = Presence.parse(parser, null); @@ -145,7 +145,7 @@ public class ConnectionIn extends Connection implements Runnable { LOGGER.info("STREAM " + streamID + " SECURED"); restartParser(); } catch (SSLException sex) { - LOGGER.warning("STREAM " + streamID + " SSL ERROR"); + LOGGER.warn("STREAM " + streamID + " SSL ERROR"); sendStanza(""); xmpp.removeConnectionIn(this); closeConnection(); @@ -156,7 +156,7 @@ public class ConnectionIn extends Connection implements Runnable { LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true)); } } - LOGGER.warning("STREAM " + streamID + " FINISHED"); + LOGGER.warn("STREAM " + streamID + " FINISHED"); xmpp.removeConnectionIn(this); closeConnection(); } catch (EOFException | SocketException ex) { @@ -164,9 +164,9 @@ public class ConnectionIn extends Connection implements Runnable { xmpp.removeConnectionIn(this); closeConnection(); } catch (HostUnknownException e) { - LOGGER.warning(e.getMessage()); + LOGGER.warn(e.getMessage()); } catch (Exception e) { - LOGGER.log(Level.WARNING, "STREAM " + streamID + " ERROR", e); + LOGGER.warn("STREAM " + streamID + " ERROR", e); xmpp.removeConnectionIn(this); closeConnection(); } @@ -198,7 +198,7 @@ public class ConnectionIn extends Connection implements Runnable { LOGGER.info("STREAM FROM " + sfrom + " " + streamID + " READY"); } } catch (IOException e) { - LOGGER.warning("STREAM FROM " + sfrom + " " + streamID + " ERROR: " + e.toString()); + LOGGER.warn("STREAM FROM " + sfrom + " " + streamID + " ERROR: " + e.toString()); } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java index cedb3745..c15a2a25 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java @@ -18,7 +18,6 @@ import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.UUID; -import java.util.logging.Level; /** * @author ugnich @@ -132,7 +131,7 @@ public class ConnectionOut extends Connection implements Runnable { restartParser(); sendOpenStream(); } catch (SSLException sex) { - logger.log(Level.SEVERE, String.format("s2s ssl error: %s %s", to, streamID), sex); + logger.error(String.format("s2s ssl error: %s %s", to, streamID), sex); sendStanza(""); xmpp.removeConnectionOut(this); closeConnection(); @@ -144,7 +143,7 @@ public class ConnectionOut extends Connection implements Runnable { } } - logger.warning("STREAM TO " + to + " " + streamID + " FINISHED"); + logger.warn("STREAM TO " + to + " " + streamID + " FINISHED"); xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (EOFException | SocketException eofex) { @@ -152,7 +151,7 @@ public class ConnectionOut extends Connection implements Runnable { xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (Exception e) { - logger.log(Level.SEVERE, String.format("s2s out exception: %s %s", to, streamID), e); + logger.error(String.format("s2s out exception: %s %s", to, streamID), e); xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } @@ -162,7 +161,7 @@ public class ConnectionOut extends Connection implements Runnable { try { sendStanza("" + key + ""); } catch (IOException e) { - logger.log(Level.WARNING, "STREAM TO " + to + " " + streamID + " ERROR", e); + logger.warn("STREAM TO " + to + " " + streamID + " ERROR", e); } } } -- cgit v1.2.3