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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Document

Is debug logging currently enabled?

Usage

From source file:org.easy.ldap.LoggingUtil.java

public static void createDebugLog(Log log, String methodName, Object... arguments) {
    if (log.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append(methodName).append("(");

        for (Object argument : arguments) {
            sb.append(argument).append(", ");
        }/* w w  w  .j a  va 2  s. co m*/

        sb.append(methodName).append(")");

        log.debug(sb.toString());
    }
}

From source file:org.easyrec.utils.spring.cache.aop.CachingAspectAdvice.java

/**
 * Takes a method name and its arguments and stores the result in a cache.
 *
 * @param pjp the JoinPoint containing information about the intercepted method call
 * @return the result of the method call
 * @throws Throwable/*from w  w  w . ja va2 s . c  o  m*/
 */
public Object cacheMethodResult(ProceedingJoinPoint pjp) throws Throwable {
    String targetName = pjp.getTarget().getClass().getName();
    String methodName = pjp.getSignature().getName();
    Object[] args = pjp.getArgs();
    Object result;

    Log logger = LogFactory.getLog(pjp.getTarget().getClass());

    if (logger.isDebugEnabled()) {
        logger.debug("looking for method " + methodName + " result in cache");
    }
    String cacheKey = getCacheKey(targetName, methodName, args);
    Element element = cache.get(cacheKey);
    if (element == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Cache miss - calling intercepted method!");
        }
        result = pjp.proceed();
        if (result == null)
            return null;
        if (logger.isDebugEnabled()) {
            logger.debug("Caching new result!");
        }
        try {
            element = new Element(cacheKey, (Serializable) result);
        } catch (Exception e) {
            logger.debug("xxResult " + result + " for key: " + cacheKey + "..." + e.getMessage());
            e.printStackTrace();
        }

        cache.put(element);
    }

    assert element != null;

    return element.getValue();
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * @param logger/*from   w w w  . j  a  v  a  2  s  . c  om*/
 * @param logLevel
 *
 */
public static boolean isLogLevelEnabled(Log logger, String logLevel) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            return true;
        }
    } else {
        logger.warn("Passed unknown log level '" + logLevel + "' to Aspect - returning false!");
        return false;
    }
    logger.warn("log level '" + logLevel + "' not enabled - returning false!");
    return false;
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 *//* w  w w  .ja  v a  2 s  .com*/
public static void log(Log logger, String logLevel, String message) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message);
    }
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 * @param ta       a Throwable passed on to the Log
 *//*from ww w.  jav  a 2 s .co  m*/
public static void log(Log logger, String logLevel, String message, Throwable ta) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message, ta);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message, ta);
    }
}

From source file:org.eclipse.smila.search.index.IndexConnection.java

/**
 * This method applies a given FieldConfig to a field.
 * /*  ww  w.  j a v a2s . c  om*/
 * @param field
 *          Search field.
 * @param nc
 *          Named config.
 * @param defaultfc
 *          Default config.
 */
private void applyFieldConfig(final DField field, final DFieldConfig nc, final DFieldConfig defaultfc) {
    final Log log = LogFactory.getLog(getClass());

    StringBuffer sb = new StringBuffer("Processing parameters for search field [" + field.getFieldNo() + "]: ");
    if (nc == null) {
        sb = sb.append("[no named config] ");
    }
    if (field.getConstraint() == null) {
        if (nc == null || nc.getConstraint() == null) {
            field.setConstraint(defaultfc.getConstraint());
            sb = sb.append("DC:");
        } else {
            field.setConstraint(nc.getConstraint());
            sb = sb.append("NC:");
        }
    }
    sb = sb.append("Constraint=" + field.getConstraint() + " ");

    if (field.getFieldTemplate() == null) {
        if (nc == null || nc.getFieldTemplate() == null) {
            field.setFieldTemplate(defaultfc.getFieldTemplate());
            sb = sb.append("DC:");
        } else {
            field.setFieldTemplate(nc.getFieldTemplate());
            sb = sb.append("NC:");
        }
    }
    sb = sb.append("FieldTemplate=" + field.getFieldTemplate() + " ");

    if (field.getNodeTransformer() == null) {
        if (nc == null || nc.getNodeTransformer() == null) {
            field.setNodeTransformer(defaultfc.getNodeTransformer());
            sb = sb.append("DC:");
        } else {
            field.setNodeTransformer(nc.getNodeTransformer());
            sb = sb.append("NC:");
        }
    }
    sb = sb.append("NodeTransformer="
            + (field.getNodeTransformer() == null ? "" : field.getNodeTransformer().getName()) + " ");

    if (field.getWeight() == null) {
        if (nc == null || nc.getWeight() == null) {
            field.setWeight(defaultfc.getWeight());
            sb = sb.append("DC:");
        } else {
            field.setWeight(nc.getWeight());
            sb = sb.append("NC:");
        }
    }
    sb = sb.append("Weight=" + field.getWeight() + " ");

    // include technologie dependant parameter assignation
    if (field instanceof org.eclipse.smila.search.utils.search.DTextField) {
        final org.eclipse.smila.search.utils.search.DTextField tf = (org.eclipse.smila.search.utils.search.DTextField) field;

        // assign named config parameters
        if (nc != null) {
            final ITFParameter tfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DTextField) nc)
                    .getParameter();
            insertTextParameter(tf, tfp, "NC", sb);
        }

        // assign default config parameters
        final ITFParameter tfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DTextField) defaultfc)
                .getParameter();
        insertTextParameter(tf, tfp, "DC", sb);

        if (tf.getParameter() != null) {
            tf.setParameter((ITFParameter) tf.getParameter().clone());
        }
    } else if (field instanceof org.eclipse.smila.search.utils.search.DNumberField) {
        final org.eclipse.smila.search.utils.search.DNumberField nf = (org.eclipse.smila.search.utils.search.DNumberField) field;

        // assign named config parameters
        if (nc != null) {
            final INFParameter nfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DNumberField) nc)
                    .getParameter();
            insertNumberParameter(nf, nfp, "NC", sb);
        }

        // assign default config parameters
        final INFParameter nfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DNumberField) defaultfc)
                .getParameter();
        insertNumberParameter(nf, nfp, "DC", sb);

        if (nf.getParameter() != null) {
            nf.setParameter((INFParameter) nf.getParameter().clone());
        }
    } else if (field instanceof org.eclipse.smila.search.utils.search.DDateField) {
        final org.eclipse.smila.search.utils.search.DDateField df = (org.eclipse.smila.search.utils.search.DDateField) field;

        // assign named config parameters
        if (nc != null) {
            final IDFParameter dfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DDateField) nc)
                    .getParameter();
            insertDateParameter(df, dfp, "NC", sb);
        }

        // assign default config parameters
        final IDFParameter dfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DDateField) defaultfc)
                .getParameter();
        insertDateParameter(df, dfp, "DC", sb);

        if (df.getParameter() != null) {
            df.setParameter((IDFParameter) df.getParameter().clone());
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(sb.toString());
    }

}

From source file:org.eclipse.smila.search.index.IndexManager.java

/**
 * Returns the instance of a requested IndexConnection by the IndexName. This method implements a pooling mechanism
 * for these Object ensuring that: - onyl one IndexConnection is used at a time - there no more than the max. # of
 * IndexConections per Index alive./*w  w  w  .  j  a va 2 s .  co  m*/
 * 
 * @param indexName
 *          Index name.
 * 
 * @return Index connection.
 * 
 * @throws IndexException
 *           Unable to get instance of index connection.
 */
public static IndexConnection getInstance(final String indexName) throws IndexException {
    final Log log = LogFactory.getLog(IndexManager.class);

    if (s_cleaner != null) {
        ; // remove compiler warning for cleaning thread.
    }
    IndexConnection indexConnection = null;
    DIndex dIndex = null;
    try {
        dIndex = DataDictionaryController.getIndex(indexName);
    } catch (final DataDictionaryException e) {
        throw new IndexException(e.getMessage());
    }
    if (dIndex == null) {
        throw new IndexException("index not in data dictionary [" + indexName + "]");
    }

    final DConnection dConnection = dIndex.getConnection();
    IndexConnectionUsage indexConUsage = null;
    IndexUsage iu = null;

    while (indexConnection == null) {

        iu = getIndexUsage(indexName);

        synchronized (iu) {
            // check if iu in SINGLE_USAGE
            if (iu._usage != Usage.Multi) {
                throw new IndexSingleUseException("index is not in multi use mode [" + indexName + "]");
            }

            // try to find iu that is not at work
            final Iterator<IndexConnectionUsage> it = iu._indexConnectionUsages.iterator();
            while (it.hasNext()) {
                indexConUsage = it.next();
                if (!indexConUsage._atWork) {
                    indexConnection = indexConUsage._indexConnection;
                    indexConUsage._atWork = true;
                    break;
                }
            }

            // no available iu exist, create new if not exceeds max
            if (indexConnection == null) {
                if (dConnection.getMaxConnections() > iu._indexConnectionUsages.size()) {
                    indexConUsage = new IndexConnectionUsage();
                    indexConUsage._atWork = true;
                    indexConUsage._idleSince = System.currentTimeMillis();
                    final Plugin plugin = PluginFactory.getPlugin();
                    indexConUsage._indexConnection = plugin.getIndexAccess().getIndexConnection(indexName);
                    indexConnection = indexConUsage._indexConnection;
                    iu._indexConnectionUsages.add(indexConUsage);
                }
            }
        } // sync iu

        if (indexConnection == null) {
            try {
                Thread.sleep(5);
            } catch (final Exception e) {
                log.error("SLEEP!", e);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("get index [" + indexConnection + "]");
    }
    return indexConnection;
}

From source file:org.eclipse.smila.search.index.IndexManager.java

/**
 * Release index connection./*from  w w  w  .  j a  v a2 s .c o m*/
 * 
 * @param indexConnection
 *          Index connection to release.
 * @param destroy
 *          Whether to destroy the index connection.
 */
public static void releaseInstance(final IndexConnection indexConnection, final boolean destroy) {
    final Log log = LogFactory.getLog(IndexManager.class);
    IndexConnectionUsage indexConUsage = null;
    final IndexUsage iu = getIndexUsage(indexConnection.getName());

    synchronized (iu) {
        final Iterator<IndexConnectionUsage> it = iu._indexConnectionUsages.iterator();
        while (it.hasNext()) {
            indexConUsage = it.next();
            if (indexConUsage._indexConnection == indexConnection) {
                indexConUsage._idleSince = System.currentTimeMillis();
                indexConUsage._atWork = false;
                if (log.isDebugEnabled()) {
                    log.debug("index released [" + indexConnection + "]");
                }
                if (destroy) {
                    it.remove();
                    indexConUsage._indexConnection.close();
                    if ((iu._indexConnectionUsages.size() == 0) && (iu._usage != Usage.None)) {
                        s_indexUsages.remove(indexConnection.getName());
                    }
                    indexConUsage._indexConnection = null;
                    indexConUsage = null;
                    if (log.isDebugEnabled()) {
                        log.debug("index destroyed [" + indexConnection + "]");
                    }
                }
                break;
            }
        }
        iu._idleSince = System.currentTimeMillis();
    } // sync iu
}

From source file:org.eclipse.smila.utils.scriptexecution.ScriptExecutorFactory.java

/**
 * Returns script executor according to current platform.
 * //w ww . j  a v  a2 s. c o m
 * @return script executor
 */
public static ScriptExecutor getScriptExecutor() {
    final Log log = LogFactory.getLog(ScriptExecutorFactory.class);
    final String platform = Platform.getOS();

    if (log.isDebugEnabled()) {
        log.debug("Getting script executor for " + platform);
    }

    if (Platform.OS_WIN32.equals(platform)) {
        return new WindowsScriptExecutor();
    } else if (Platform.OS_LINUX.equals(platform) || Platform.OS_SOLARIS.equals(platform)) {
        return new UnixScriptExecutor();
    } else {
        throw new IllegalStateException("Valid script executor is missing for [" + platform + "] platform.");
    }
}

From source file:org.elasticsearch.client.RequestLogger.java

/**
 * Logs a request that yielded a response
 */// ww w. j  a va  2s  .co  m
static void logResponse(Log logger, HttpUriRequest request, HttpHost host, HttpResponse httpResponse) {
    if (logger.isDebugEnabled()) {
        logger.debug("request [" + request.getMethod() + " " + host + getUri(request.getRequestLine())
                + "] returned [" + httpResponse.getStatusLine() + "]");
    }
    if (logger.isWarnEnabled()) {
        Header[] warnings = httpResponse.getHeaders("Warning");
        if (warnings != null && warnings.length > 0) {
            logger.warn(buildWarningMessage(request, host, warnings));
        }
    }
    if (tracer.isTraceEnabled()) {
        String requestLine;
        try {
            requestLine = buildTraceRequest(request, host);
        } catch (IOException e) {
            requestLine = "";
            tracer.trace("error while reading request for trace purposes", e);
        }
        String responseLine;
        try {
            responseLine = buildTraceResponse(httpResponse);
        } catch (IOException e) {
            responseLine = "";
            tracer.trace("error while reading response for trace purposes", e);
        }
        tracer.trace(requestLine + '\n' + responseLine);
    }
}