The PKI server logging service has been modified to utilize SLF4J internally while maintaining the same API. This will allow incremental transition to SLF4J.
https://fedorahosted.org/pki/ticket/195 -- Endi S. Dewata
>From ac10c328028d332e047358721de2cda3c56bc6c8 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" <edew...@redhat.com> Date: Fri, 18 Nov 2016 00:54:57 +0100 Subject: [PATCH] Updated PKI server logging service to use SLF4J. The PKI server logging service has been modified to utilize SLF4J internally while maintaining the same API. This will allow incremental transition to SLF4J. https://fedorahosted.org/pki/ticket/195 --- base/server/cmscore/src/CMakeLists.txt | 3 +- .../src/com/netscape/cmscore/util/Debug.java | 74 +++++++--------------- 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/base/server/cmscore/src/CMakeLists.txt b/base/server/cmscore/src/CMakeLists.txt index 4ac1d46f30efd9153f2cfa6b966173ce4622d55a..3b36550b3789880d08ef8242ebcec41407553a19 100644 --- a/base/server/cmscore/src/CMakeLists.txt +++ b/base/server/cmscore/src/CMakeLists.txt @@ -124,14 +124,15 @@ javac(pki-cmscore-classes SOURCES *.java CLASSPATH - ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR} ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_TOMCAT_JAR} ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR} ${XALAN_JAR} ${XERCES_JAR} ${JSS_JAR} ${COMMONS_CODEC_JAR} ${COMMONS_HTTPCLIENT_JAR} ${APACHE_COMMONS_LANG_JAR} ${TOMCAT_CATALINA_JAR} ${TOMCAT_UTIL_JAR} ${SYMKEY_JAR} ${JAXRS_API_JAR} ${RESTEASY_JAXRS_JAR} ${RESTEASY_ATOM_PROVIDER_JAR} ${HTTPCLIENT_JAR} ${HTTPCORE_JAR} + ${SLF4J_API_JAR} ${NUXWDOG_JAR} + ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR} ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_TOMCAT_JAR} OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/classes DEPENDS diff --git a/base/server/cmscore/src/com/netscape/cmscore/util/Debug.java b/base/server/cmscore/src/com/netscape/cmscore/util/Debug.java index 83c0e1b06826422741e143810e701d6b78b41492..95759513ddaeaa3edec8a332582d96a1c9f7282d 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/util/Debug.java +++ b/base/server/cmscore/src/com/netscape/cmscore/util/Debug.java @@ -17,22 +17,21 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Date; import java.util.Hashtable; import java.util.StringTokenizer; import org.apache.commons.lang.time.FastDateFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISubsystem; -import com.netscape.cmsutil.util.Utils; public class Debug implements ISubsystem { + private static Logger logger = LoggerFactory.getLogger(Debug.class); + private static Debug mInstance = new Debug(); private static boolean mShowCaller = false; @@ -58,15 +57,8 @@ public class Debug private static int mDebugLevel = VERBOSE; - private static PrintStream mOut = null; private static Hashtable<String, String> mHK = null; - static { - if (TRACE_ON == true) { - mOut = System.out; - } - } - public static void trace(int level, String t) { trace(level, t, null, true); } @@ -135,10 +127,7 @@ public class Debug private static void outputTraceMessage(String t) { if (!TRACE_ON) return; - if (mOut != null) { - mOut.println("[" + df.format(new Date()) + "][" + Thread.currentThread().getName() + "]: " + t); - mOut.flush(); - } + logger.debug("[" + Thread.currentThread().getName() + "] " + t); } private static boolean hkdotype(String type) { @@ -181,9 +170,17 @@ public class Debug public static void print(int level, String t) { if (!TRACE_ON) return; - if (mOut != null) { - if (level >= mDebugLevel) - mOut.print(t); + if (level < mDebugLevel) + return; + + if (level == INFORM) { + logger.warn(t); + + } else if (level == VERBOSE) { + logger.info(t); + + } else { // level == OBNOXIOUS + logger.debug(t); } } @@ -191,15 +188,6 @@ public class Debug print(VERBOSE, t); } - private static void printNybble(byte b) { - if (mOut == null) - return; - if (b < 10) - mOut.write('0' + b); - else - mOut.write('a' + b - 10); - } - /** * If tracing enabled, dump a byte array to debugging printstream * as hex, colon-seperated bytes, 16 bytes to a line @@ -207,18 +195,17 @@ public class Debug public static void print(byte[] b) { if (!TRACE_ON) return; - if (mOut == null) - return; + + StringBuilder sb = new StringBuilder(); + sb.append("Data:\n"); for (int i = 0; i < b.length; i++) { - printNybble((byte) ((b[i] & 0xf0) >> 4)); - printNybble((byte) (b[i] & 0x0f)); - mOut.print(" "); + sb.append(String.format(" %02x", b[i])); if (((i % 16) == 15) && i != b.length) - mOut.println(""); + sb.append("\n"); } - mOut.println(""); - mOut.flush(); + + logger.info(sb.toString()); } /** @@ -239,10 +226,8 @@ public class Debug public static void printStackTrace(Throwable e) { if (!TRACE_ON) return; - if (mOut == null) - return; - e.printStackTrace(mOut); + logger.error(e.getMessage(), e); } /** @@ -322,17 +307,6 @@ public class Debug append = mConfig.getBoolean(PROP_APPEND, true); } if (TRACE_ON) { - if (filename.equals("STDOUT")) { - mOut = System.out; - } else { - if (!Utils.isNT()) { - // Always insure that a physical file exists! - Utils.exec("touch " + filename); - Utils.exec("chmod 00640 " + filename); - } - OutputStream os = new FileOutputStream(filename, append); - mOut = new PrintStream(os, true); /* true == autoflush */ - } if (hashkeytypes != null) { StringTokenizer st = new StringTokenizer(hashkeytypes, ",", false); -- 2.5.5
_______________________________________________ Pki-devel mailing list Pki-devel@redhat.com https://www.redhat.com/mailman/listinfo/pki-devel