On 11/18/2016 3:00 PM, Endi Sukma Dewata wrote:
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
New patch attached for some cleanups.
--
Endi S. Dewata
>From 6f10b11edb6bf842d543698085fbfbb654770848 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <[email protected]>
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. The log level of PKI
packages will be determined by the existing debug.level parameter.
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 | 93 ++++++++++------------
2 files changed, 45 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..e5ffffc102e2e1c806a3b8dbab1a8b32abed93a2 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,22 @@
// --- 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 java.util.logging.Level;
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 +58,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 +128,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 +171,15 @@ 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 <= OBNOXIOUS) {
+ logger.debug(t);
+
+ } else if (level <= VERBOSE) {
+ logger.info(t);
+
+ } else { // if (level <= INFORM)
+ logger.warn(t);
}
}
@@ -191,15 +187,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 +194,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 +225,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);
}
/**
@@ -259,6 +243,26 @@ public class Debug
public static void setLevel(int level) {
mDebugLevel = level;
+
+ // translate debug.level into JUL logger level
+ Level loggerLevel;
+
+ if (level <= 0) {
+ loggerLevel = Level.ALL;
+
+ } else if (level <= OBNOXIOUS) {
+ loggerLevel = Level.FINE;
+
+ } else if (level <= VERBOSE){
+ loggerLevel = Level.INFO;
+
+ } else { // if (level <= INFORM)
+ loggerLevel = Level.WARNING;
+ }
+
+ java.util.logging.Logger.getLogger("org.dogtagpki").setLevel(loggerLevel);
+ java.util.logging.Logger.getLogger("com.netscape").setLevel(loggerLevel);
+ java.util.logging.Logger.getLogger("netscape").setLevel(loggerLevel);
}
public static int getLevel(int level) {
@@ -322,17 +326,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
[email protected]
https://www.redhat.com/mailman/listinfo/pki-devel