Example usage for org.apache.commons.logging Log debug

List of usage examples for org.apache.commons.logging Log debug

Introduction

In this page you can find the example usage for org.apache.commons.logging Log debug.

Prototype

void debug(Object message);

Source Link

Document

Logs a message with debug log level.

Usage

From source file:org.hyperic.util.file.match.Matcher.java

/**
 * Get the matches for this search./*w  ww.j a v a2s.  c  o m*/
 * @return A Map representing the matches.  The keys in the Map are
 * the keys that each MatchSelector in the MatcherConfig was
 * initialized with in its constructor.  The values are Lists, where
 * each element in the List is a String representing the full path
 * of the matched path.
 * @exception MatcherInterruptedException If the search was interrupted
 * before it could be completed.  In this case, you can get the matches
 * so far by calling getMatchesSoFar on the MatcherInterruptedException
 * object.
 * @exception SigarException If an error occurs reading the available
 * filesystems - this can only happen if the config's getFSTypes returns
 * a value other than MatcherConfig.FS_ALL.
 */
public synchronized MatchResults getMatches(MatcherConfig config)
        throws MatcherInterruptedException, SigarException {

    int i, j;
    List scanners;
    MatcherScanner scanner;
    MatchResults results = new MatchResults();
    File f;
    Log log = config.getLog();
    FileSystem[] filesystems = null;

    filesystems = loadFilesystems(config);
    scanners = initScanners(config, filesystems, results);

    for (i = 0; i < scanners.size(); i++) {

        scanner = (MatcherScanner) scanners.get(i);
        scanner.initMatches(results.matches);

        try {
            scanner.doScan();

        } catch (MatcherInterruptedException mie) {
            mie.setMatchesSoFar(scanner.getMatches());
            if (log != null) {
                log.warn("matcher: search interrupted.");
            }
            throw mie;

        } catch (Exception e) {
            // huh?
            scanner.addError(new MatcherException("matcher: search error", e));
            if (log != null) {
                log.error("matcher: search error: " + e, e);
            }
        }

        results.matches = scanner.getMatches();
        if (log != null) {
            log.debug("results.matches=" + results.matches);
        }
        results.errors.addAll(scanner.getErrors());
    }

    return results;
}

From source file:org.impalaframework.extension.mvc.util.RequestModelHelper.java

/**
 * /*  w w w . j a  va2  s .  c o m*/
 * @param logger
 * @param request
 */
public static void maybeDebugRequest(Log logger, HttpServletRequest request) {

    if (logger.isDebugEnabled()) {

        logger.debug("#####################################################################################");
        logger.debug("---------------------------- Request details ---------------------------------------");
        logger.debug("Request context path: " + request.getContextPath());
        logger.debug("Request path info: " + request.getPathInfo());
        logger.debug("Request path translated: " + request.getPathTranslated());
        logger.debug("Request query string: " + request.getQueryString());
        logger.debug("Request servlet path: " + request.getServletPath());
        logger.debug("Request request URI: " + request.getRequestURI());
        logger.debug("Request request URL: " + request.getRequestURL());
        logger.debug("Request session ID: " + request.getRequestedSessionId());

        logger.debug("------------------------------------------------ ");
        logger.debug("Parameters ------------------------------------- ");
        final Enumeration<String> parameterNames = request.getParameterNames();

        Map<String, String> parameters = new TreeMap<String, String>();

        while (parameterNames.hasMoreElements()) {
            String name = parameterNames.nextElement();
            String value = request.getParameter(name);
            final String lowerCase = name.toLowerCase();
            if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) {
                value = "HIDDEN";
            }
            parameters.put(name, value);
        }

        //now output            
        final Set<String> parameterKeys = parameters.keySet();
        for (String key : parameterKeys) {
            logger.debug(key + ": " + parameters.get(key));
        }

        logger.debug("------------------------------------------------ ");

        Map<String, Object> attributes = new TreeMap<String, Object>();

        logger.debug("Attributes ------------------------------------- ");
        final Enumeration<String> attributeNames = request.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            String name = attributeNames.nextElement();
            Object value = request.getAttribute(name);
            final String lowerCase = name.toLowerCase();
            if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) {
                value = "HIDDEN";
            }
            attributes.put(name, value);
        }

        //now output
        final Set<String> keys = attributes.keySet();
        for (String name : keys) {
            Object value = attributes.get(name);
            logger.debug(name + ": " + (value != null ? value.toString() : value));
        }

        logger.debug("------------------------------------------------ ");
        logger.debug("#####################################################################################");
    } else {
        if (logger.isInfoEnabled()) {
            logger.info(
                    "#####################################################################################");
            logger.info("Request query string: " + request.getQueryString());
            logger.info("Request request URI: " + request.getRequestURI());
            logger.info(
                    "#####################################################################################");
        }
    }
}

From source file:org.impalaframework.web.utils.WebPathUtils.java

public static void maybeLogRequest(HttpServletRequest request, Log logger) {

    if (logger.isDebugEnabled()) {
        logger.debug("Request context path: " + request.getContextPath());
        logger.debug("Request local address: " + request.getLocalAddr());
        logger.debug("Request local name: " + request.getLocalName());
        logger.debug("Request path info: " + request.getPathInfo());
        logger.debug("Request path translated: " + request.getPathTranslated());
        logger.debug("Request query string: " + request.getQueryString());
        logger.debug("Request servlet path: " + request.getServletPath());
        logger.debug("Request request URI: " + request.getRequestURI());
        logger.debug("Request request URL: " + request.getRequestURL());
        logger.debug("Request session ID: " + request.getRequestedSessionId());
    }//from w  ww .j  a v a  2 s  .c  o m
}

From source file:org.inwiss.platform.common.util.ConvertUtil.java

/**
 * Converts string to byte array according to specified encoding
 *
 * @param content  String to convert to array
 * @param encoding Encoding string, if <code>null</code> default is used
 * @return byte array// ww w  .ja  va2s .  c  om
 */
public static byte[] convertToByteArray(String content, String encoding) {

    Log log = LogFactory.getLog(ConvertUtil.class);

    if (content == null) {
        return null;
    }
    if (encoding == null) {
        encoding = Constants.DEFAULT_ENCODING;
    }

    if (log.isDebugEnabled()) {
        log.debug("Converting to byte array using: " + encoding);
    }

    byte[] value;
    try {
        value = content.getBytes(encoding);
    } catch (UnsupportedEncodingException ex) {
        if (log.isWarnEnabled()) {
            log.warn(ex);
        }
        return content.getBytes();
    }
    return value;
}

From source file:org.jasig.portal.spring.PortalApplicationContextLocator.java

/**
 * If running in a web application the existing {@link WebApplicationContext} will be returned. if
 * not a singleton {@link ApplicationContext} is created if needed and returned. Unless a {@link WebApplicationContext}
 * is specifically needed this method should be used as it will work both when running in and out
 * of a web application//from   w ww .  j  a  va  2s.c o  m
 * 
 * @return The {@link ApplicationContext} for the portal. 
 */
public static ApplicationContext getApplicationContext() {
    Log logger = LogFactory.getLog(LOGGER_NAME);
    final ServletContext context = servletContext;

    if (context != null) {
        logger.debug("Using WebApplicationContext");

        if (applicationContextCreator.isCreated()) {
            final IllegalStateException createException = new IllegalStateException(
                    "A portal managed ApplicationContext has already been created but now a ServletContext is available and a WebApplicationContext will be returned. "
                            + "This situation should be resolved by delaying calls to this class until after the web-application has completely initialized.");
            logger.error(createException, createException);
            logger.error("Stack trace of original ApplicationContext creator", directCreatorThrowable);
            throw createException;
        }

        final WebApplicationContext webApplicationContext = WebApplicationContextUtils
                .getWebApplicationContext(context);
        if (webApplicationContext == null) {
            throw new IllegalStateException(
                    "ServletContext is available but WebApplicationContextUtils.getWebApplicationContext(ServletContext) returned null. Either the application context failed to load or is not yet done loading.");
        }
        return webApplicationContext;
    }

    return applicationContextCreator.get();
}

From source file:org.jasig.portal.utils.threading.DoubleCheckedCreator.java

/**
 * Double checking retrieval/creation of an object
 * //from   w  ww. j  a va2  s .c o  m
 * @param args Optional arguments to pass to {@link #retrieve(Object...)}, {@link #create(Object...)}, and {@link #invalid(Object, Object...)}.
 * @return A retrieved or created object.
 */
public final T get(Object... args) {
    final Log logger = LogFactory.getLog(LOGGER_NAME);
    //Grab a read lock to try retrieving the object
    this.readLock.lock();
    try {

        //See if the object already exists and is valid
        final T value = this.retrieve(args);
        if (!this.invalid(value, args)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Using retrieved Object='" + value + "'");
            }

            return value;
        }
    } finally {
        //Release the read lock
        this.readLock.unlock();
    }

    //Object must not be valid, switch to a write lock
    this.writeLock.lock();
    try {
        //Check again if the object exists and is valid
        T value = this.retrieve(args);
        if (this.invalid(value, args)) {

            //Object is not valid, create it
            value = this.create(args);

            if (logger.isDebugEnabled()) {
                logger.debug("Created new Object='" + value + "'");
            }
        } else if (logger.isDebugEnabled()) {
            logger.debug("Using retrieved Object='" + value + "'");
        }

        return value;
    } finally {
        //switch back to the read lock
        this.writeLock.unlock();
    }
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoader.java

/**
 * Initialize Spring's portlet application context for the given portlet context,
 * using the application context provided at construction time, or creating a new one
 * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and
 * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params.
 * @param portletContext current portlet context
 * @return the new PortletApplicationContext
 * @see #CONTEXT_CLASS_PARAM//from  w ww .ja va 2s. c om
 * @see #CONFIG_LOCATION_PARAM
 */
public PortletApplicationContext initWebApplicationContext(PortletContext portletContext) {
    if (portletContext
            .getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException(
                "Cannot initialize context because there is already a root portlet application context present - "
                        + "check whether you have multiple PortletContextLoader* definitions in your portlet.xml!");
    }

    Log logger = LogFactory.getLog(PortletContextLoader.class);
    portletContext.log("Initializing Spring root PortletApplicationContext");
    if (logger.isInfoEnabled()) {
        logger.info("Root portlet PortletApplicationContext: initialization started");
    }
    long startTime = System.nanoTime();

    try {
        // Store context in local instance variable, to guarantee that
        // it is available on PortletContext shutdown.
        if (this.context == null) {
            this.context = createPortletApplicationContext(portletContext);
        }
        if (this.context instanceof ConfigurablePortletApplicationContext) {
            configureAndRefreshPortletApplicationContext((ConfigurablePortletApplicationContext) this.context,
                    portletContext);
        }
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE,
                this.context);

        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        if (ccl == PortletContextLoader.class.getClassLoader()) {
            currentContext = this.context;
        } else if (ccl != null) {
            currentContextPerThread.put(ccl, this.context);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Published root PortletApplicationContext as PortletContext attribute with name ["
                    + PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        if (logger.isInfoEnabled()) {
            long elapsedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
            logger.info("Root PortletApplicationContext: initialization completed in " + elapsedTime + " ms");
        }

        return this.context;
    } catch (RuntimeException ex) {
        logger.error("Portlet context initialization failed", ex);
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error err) {
        logger.error("Portlet context initialization failed", err);
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE, err);
        throw err;
    }
}

From source file:org.java.plugin.ObjectFactory.java

/**
 * Creates and configures new instance of object factory. Factory
 * implementation class discovery procedure is following:
 * <ul>//  w w w .ja v a  2s .com
 *   <li>Use the <code>org.java.plugin.ObjectFactory</code> property from
 *     the given properties collection (if it is provided).</li>
 *   <li>Use the <code>org.java.plugin.ObjectFactory</code> system
 *   property.</li>
 *   <li>Use the properties file "jpf.properties" in the JRE "lib"
 *   directory or in the CLASSPATH. This configuration file is in standard
 *   <code>java.util.Properties</code> format and contains among others the
 *   fully qualified name of the implementation class with the key being the
 *   system property defined above.</li>
 *   <li>Use the Services API (as detailed in the JAR specification), if
 *   available, to determine the class name. The Services API will look for
 *   a class name in the file
 *   <code>META-INF/services/org.java.plugin.ObjectFactory</code> in jars
 *   available to the runtime.</li>
 *   <li>Framework default <code>ObjectFactory</code> implementation.</li>
 * </ul>
 * @param config factory configuration data, may be <code>null</code>
 * @return configured instance of object factory
 */
public static ObjectFactory newInstance(final ExtendedProperties config) {
    Log log = LogFactory.getLog(ObjectFactory.class);
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
        cl = ObjectFactory.class.getClassLoader();
    }
    ExtendedProperties props;
    if (config != null) {
        props = config;
    } else {
        props = loadProperties(cl);
    }
    String className = findProperty(cl, props);
    ObjectFactory result;
    try {
        if (className == null) {
            className = "org.java.plugin.standard.StandardObjectFactory"; //$NON-NLS-1$
        }
        result = (ObjectFactory) loadClass(cl, className).newInstance();
    } catch (ClassNotFoundException cnfe) {
        log.fatal("failed instantiating object factory " //$NON-NLS-1$
                + className, cnfe);
        throw new Error("failed instantiating object factory " //$NON-NLS-1$
                + className, cnfe);
    } catch (IllegalAccessException iae) {
        log.fatal("failed instantiating object factory " //$NON-NLS-1$
                + className, iae);
        throw new Error("failed instantiating object factory " //$NON-NLS-1$
                + className, iae);
    } catch (SecurityException se) {
        log.fatal("failed instantiating object factory " //$NON-NLS-1$
                + className, se);
        throw new Error("failed instantiating object factory " //$NON-NLS-1$
                + className, se);
    } catch (InstantiationException ie) {
        log.fatal("failed instantiating object factory " //$NON-NLS-1$
                + className, ie);
        throw new Error("failed instantiating object factory " //$NON-NLS-1$
                + className, ie);
    }
    result.configure(props);
    log.debug("object factory instance created - " + result); //$NON-NLS-1$
    return result;
}

From source file:org.java.plugin.ObjectFactory.java

private static ExtendedProperties loadProperties(final ClassLoader cl) {
    Log log = LogFactory.getLog(ObjectFactory.class);
    File file = new File(System.getProperty("java.home") //$NON-NLS-1$
            + File.separator + "lib" + File.separator //$NON-NLS-1$
            + "jpf.properties"); //$NON-NLS-1$
    URL url = null;//  ww  w  . j a v  a2s  . com
    if (file.canRead()) {
        try {
            url = IoUtil.file2url(file);
        } catch (MalformedURLException mue) {
            log.error("failed converting file " + file //$NON-NLS-1$
                    + " to URL", mue); //$NON-NLS-1$
        }
    }
    if (url == null) {
        if (cl != null) {
            url = cl.getResource("jpf.properties"); //$NON-NLS-1$
            if (url == null) {
                url = ClassLoader.getSystemResource("jpf.properties"); //$NON-NLS-1$
            }
        } else {
            url = ClassLoader.getSystemResource("jpf.properties"); //$NON-NLS-1$
        }
        if (url == null) {
            log.debug("no jpf.properties file found in ${java.home}/lib (" //$NON-NLS-1$
                    + file + ") nor in CLASSPATH, using standard properties"); //$NON-NLS-1$
            url = StandardObjectFactory.class.getResource("jpf.properties"); //$NON-NLS-1$
        }
    }
    try {
        InputStream strm = IoUtil.getResourceInputStream(url);
        try {
            ExtendedProperties props = new ExtendedProperties();
            props.load(strm);
            log.debug("loaded jpf.properties from " + url); //$NON-NLS-1$
            return props;
        } finally {
            try {
                strm.close();
            } catch (IOException ioe) {
                // ignore
            }
        }
    } catch (Exception e) {
        log.error("failed loading jpf.properties from CLASSPATH", //$NON-NLS-1$
                e);
    }
    return null;
}

From source file:org.java.plugin.ObjectFactory.java

private static String findProperty(final ClassLoader cl, final ExtendedProperties props) {
    Log log = LogFactory.getLog(ObjectFactory.class);
    String name = ObjectFactory.class.getName();
    String result = System.getProperty(name);
    if (result != null) {
        log.debug("property " + name //$NON-NLS-1$
                + " found as system property"); //$NON-NLS-1$
        return result;
    }/*from w  ww  .  j  a  va  2s.  c o  m*/
    if (props != null) {
        result = props.getProperty(name);
        if (result != null) {
            log.debug("property " + name //$NON-NLS-1$
                    + " found in properties file"); //$NON-NLS-1$
            return result;
        }
    }
    String serviceId = "META-INF/services/" //$NON-NLS-1$
            + ObjectFactory.class.getName();
    InputStream strm;
    if (cl == null) {
        strm = ClassLoader.getSystemResourceAsStream(serviceId);
    } else {
        strm = cl.getResourceAsStream(serviceId);
    }
    if (strm != null) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(strm, "UTF-8")); //$NON-NLS-1$
            try {
                result = reader.readLine();
            } finally {
                try {
                    reader.close();
                } catch (IOException ioe) {
                    // ignore
                }
            }
        } catch (IOException ioe) {
            try {
                strm.close();
            } catch (IOException ioe2) {
                // ignore
            }
        }
    }
    if (result != null) {
        log.debug("property " + name //$NON-NLS-1$
                + " found as service"); //$NON-NLS-1$
        return result;
    }
    log.debug("no property " + name //$NON-NLS-1$
            + " found"); //$NON-NLS-1$
    return result;
}