FormsLogger.java 10.2 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.logging.AdobeLogger
 *  com.adobe.logging.Msg0
 *  com.adobe.logging.Msg1
 *  com.adobe.logging.Msg2
 *  com.adobe.logging.Msg3
 *  com.adobe.service.logging.Level
 */
package com.adobe.livecycle.formsservice.logging;

import com.adobe.livecycle.formsservice.client.RenderOptionsSpec;
import com.adobe.logging.AdobeLogger;
import com.adobe.logging.Msg0;
import com.adobe.logging.Msg1;
import com.adobe.logging.Msg2;
import com.adobe.logging.Msg3;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;

public class FormsLogger {
    public static final int LOG_FATAL = 0;
    public static final int LOG_ALERT = 1;
    public static final int LOG_CRITICAL = 2;
    public static final int LOG_ERROR = 3;
    public static final int LOG_WARN = 4;
    public static final int LOG_NOTICE = 5;
    public static final int LOG_INFO = 6;
    public static final int LOG_DEBUG = 7;
    public static final int LOG_PERFORMANCE = 5;
    public static final String NEWLINE = System.getProperty("java.line.separator");
    public static final String FRM_PERF_KW = "ALC-FRM-PRF:";
    public static final String OUT_PERF_KW = "ALC-OUT-PRF:";
    public static final String PERF_KW = " !PERFORMANCE! ";
    public static final String DEF_FS_LOGGING_BUNDLE = "com.adobe.livecycle.formsservice.logging.FRM";
    public static final String SERVICE_FORMS = "FormsService";
    public static final String SERVICE_OUTPUT = "OutputService";
    public static Boolean bIsDebugLevel = null;
    private static final String FORM_KEY = "Form Query or UUID : [";
    private static final String CONTENT_ROOT_URI = "Content Root Uri : [";
    private static final String NO_FORMS_KEY_SET = "No Form Key Set";
    private static final char CLOSE_PAREN = ']';
    private static ThreadLocal<String> serviceName = new ThreadLocal();
    private static ThreadLocal<Boolean> bPerfLoggingEnabled = new ThreadLocal();
    private static ThreadLocal<ArrayList<String>> oTLBuffer = new ThreadLocal();
    private static ThreadLocal<String> formsKeys = new ThreadLocal();

    public static String getResourceString(ResourceBundle bundle, String resourceID) {
        return FormsLogger.getResourceString(bundle, resourceID, Locale.getDefault());
    }

    public static String getResourceString(ResourceBundle bundle, String resourceID, Locale locale) {
        if (bundle == null) {
            bundle = ResourceBundle.getBundle("com.adobe.livecycle.formsservice.logging.FRM", locale);
        }
        return (String)bundle.getObject(resourceID);
    }

    public static String getResourceString(String resourceID) {
        return FormsLogger.getResourceString(null, resourceID);
    }

    public static String getResourceString(String resourceID, Locale locale) {
        return FormsLogger.getResourceString(null, resourceID, locale);
    }

    public static String getResourceString(ResourceBundle bundle, String resourceID, String[] args) {
        return FormsLogger.getResourceString(bundle, resourceID, Locale.getDefault(), args);
    }

    public static String getResourceString(ResourceBundle bundle, String resourceID, Locale locale, String[] args) {
        if (bundle == null) {
            bundle = ResourceBundle.getBundle("com.adobe.livecycle.formsservice.logging.FRM");
        }
        String res = (String)bundle.getObject(resourceID);
        if (args != null) {
            for (int i = 0; i < args.length; ++i) {
                String tok = "{" + i + "}";
                int j = res.indexOf(tok);
                if (j < 0) continue;
                res = res.substring(0, j) + args[i] + res.substring(j + tok.length());
            }
        }
        return res;
    }

    public static String getResourceString(String resourceID, String[] args) {
        return FormsLogger.getResourceString(null, resourceID, args);
    }

    public static String getResourceString(String resourceID, Locale locale, String[] args) {
        return FormsLogger.getResourceString(null, resourceID, locale, args);
    }

    public static void logMessage(Class oClass, int severity, ResourceBundle bundle, String resourceID) {
        FormsLogger.logMessage(oClass, severity, bundle, resourceID, null);
    }

    public static void logMessage(Class oClass, int severity, String resourceID) {
        FormsLogger.logMessage(oClass, severity, null, resourceID);
    }

    public static void logMessage(Class oClass, int severity, String resourceID, String[] args) {
        FormsLogger.logMessage(oClass, severity, null, resourceID, args);
    }

    public static void logMessage(Class oClass, int severity, ResourceBundle bundle, String resourceID, String[] args) {
        try {
            String sLogString = FormsLogger.getResourceString(bundle, resourceID);
            if (sLogString == null || sLogString.length() == 0) {
                sLogString = "** this msg not found in resources **";
            }
            AdobeLogger logger = AdobeLogger.getAdobeLogger((Class)oClass);
            com.adobe.service.logging.Level adobeLevel = com.adobe.service.logging.Level.toLevel((int)severity);
            if (serviceName.get() != null && serviceName.get().equalsIgnoreCase("OutputService")) {
                resourceID = resourceID.substring(0, 3) + "-OUT-002-" + resourceID.substring(12, 15);
            }
            if (args == null) {
                logger.log(new Msg0(resourceID, adobeLevel.jdkLevel(), sLogString));
            } else if (args.length == 1) {
                logger.log(new Msg1(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0]);
            } else if (args.length == 2) {
                logger.log(new Msg2(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0], (Object)args[1]);
            } else if (args.length >= 3) {
                logger.log(new Msg3(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0], (Object)args[1], (Object)args[2]);
            }
        }
        catch (Exception e) {
            String err = e.getMessage();
            if (err == null) {
                err = e.getClass().getName();
            }
            System.out.print("[FormServer] logMessage error: " + e + " args passed: ");
            for (int i = 0; i < args.length; ++i) {
                System.out.print(args[i]);
            }
            System.out.println("");
        }
    }

    public static void logInfo(Class oClass, String text) {
        FormsLogger.logMessage(oClass, 6, "ALC-FRM-001-501", new String[]{text});
    }

    public static void logDebug(Class oClass, String text) {
        FormsLogger.logMessage(oClass, 7, "ALC-FRM-001-501", new String[]{text});
    }

    public static long logPerformance(boolean diff, long timeStamp, String text) {
        if (!FormsLogger.getPerformanceLogEnabled()) {
            return -1;
        }
        if (!diff) {
            FormsLogger.logPMessage(new String[]{text});
            return System.nanoTime();
        }
        long difference = System.nanoTime() - timeStamp;
        FormsLogger.logPMessage(new String[]{text, "" + difference});
        return 0;
    }

    private static void logPMessage(String[] args) {
        ArrayList<String> oThreadLocalBuffer = FormsLogger.getBuffer();
        if (oThreadLocalBuffer != null) {
            StringBuffer oMsg = new StringBuffer();
            if (serviceName.get() != null && serviceName.get().equalsIgnoreCase("OutputService")) {
                oMsg.append("ALC-OUT-PRF:");
            } else {
                oMsg.append("ALC-FRM-PRF:");
            }
            oMsg.append(" !PERFORMANCE! ");
            if (args.length == 1) {
                oMsg.append(args[0]);
            } else if (args.length == 2) {
                oMsg.append(args[0]).append(" :").append(args[1]).append("ns");
            }
            oThreadLocalBuffer.add(oMsg.toString());
        }
    }

    public static void logFormRenderRequestInfo(Class oClass, String sFormQuery, String sFormPreference, RenderOptionsSpec cOptionsBean, String sUserAgent, String sApplicationWebRoot, String sTargetURL, String sContentRootURI, String sBaseURL) {
        StringBuffer logBuffer = new StringBuffer();
        logBuffer.append("FormName: ").append(sFormQuery).append(", FormPreference: ").append(sFormPreference).append(", Debug: ").append(cOptionsBean.isDebugEnabled()).append(", PDFVersion: ").append(cOptionsBean.getPDFVersion()).append(", Content Root: ").append(sContentRootURI).append(", Base URL: ").append(sBaseURL).append(", App Root: ").append(sApplicationWebRoot).append(", User Agent: ").append(sUserAgent);
        FormsLogger.logMessage(oClass, 7, "ALC-FRM-001-501", new String[]{logBuffer.toString()});
    }

    public static ArrayList<String> getBuffer() {
        return oTLBuffer.get();
    }

    public static void setBuffer(ArrayList<String> oList) {
        oTLBuffer.set(oList);
    }

    public static boolean getPerformanceLogEnabled() {
        return bPerfLoggingEnabled.get() != null && bPerfLoggingEnabled.get() != false;
    }

    public static void setPerformanceLogEnabled(boolean bEnable) {
        bPerfLoggingEnabled.set(bEnable);
    }

    public static void setServiceName(String name) {
        serviceName.set(name);
    }

    public static void setFormKey(String key, String contentRootUri) {
        if (FormsLogger.getPerformanceLogEnabled()) {
            StringBuffer strBuffer = new StringBuffer(100);
            if (key != null && key.length() > 0) {
                strBuffer.append("Form Query or UUID : [" + key).append(']');
            } else {
                strBuffer.append("No Form Key Set");
            }
            if (contentRootUri != null && contentRootUri.length() > 0) {
                strBuffer.append(',').append("Content Root Uri : [").append(contentRootUri).append(']');
            }
            formsKeys.set(strBuffer.toString());
        }
    }

    public static String getFormKey() {
        return formsKeys.get();
    }

    public static boolean isDebugLevel(Class oClass) {
        AdobeLogger oLogger = AdobeLogger.getAdobeLogger((Class)oClass);
        if (oLogger == null) {
            return false;
        }
        return oLogger.isLoggable(com.adobe.service.logging.Level.DEBUG.jdkLevel());
    }
}