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

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

Introduction

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

Prototype

boolean isInfoEnabled();

Source Link

Document

Is info logging currently enabled?

Usage

From source file:com.CodeSeance.JSeance.CodeGenXML.XMLElements.Template.java

public static String run(File templateFile, File includesDir, File modelsDir, File targetDir,
        boolean ignoreReadOnlyOuputFiles, TemplateDependencies templateDependencies) {
    // Create a local logger for the static context
    Log log = com.CodeSeance.JSeance.CodeGenXML.Runtime.CreateLogger(Template.class);

    if (log.isInfoEnabled()) {
        log.info(String.format("Loading Template:[%s]", templateFile.toString()));
    }/*ww  w .  ja v  a 2  s  . co m*/

    // Load the default schema validator
    XMLLoader xmlLoader = XMLLoader.buildFromCodeTemplateSchema();

    // Loads the XML document
    Document document;
    try {
        InputStream inputStream = new FileInputStream(templateFile);
        document = xmlLoader.loadXML(inputStream);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ExecutionError.INVALID_TEMPLATE_FILE.getMessage(templateFile.toString()),
                ex);
    } catch (SAXException ex) {
        throw new RuntimeException(
                ExecutionError.INVALID_TEMPLATE_XML.getMessage(templateFile.toString(), ex.getMessage()), ex);
    }

    // Load the object hierarchy from the XMLDocument
    Template template = new Template(document.getDocumentElement());

    if (log.isInfoEnabled()) {
        log.info("XMLSchema validated");
    }

    // Create a new ContextManager
    ContextManager contextManager = new ContextManager(includesDir, modelsDir, targetDir,
            ignoreReadOnlyOuputFiles, templateDependencies);

    try {
        // Enter and leave the context on the new template element
        template.onContextEnter(contextManager.getCurrentContext());
        template.onContextExit(contextManager.getCurrentContext());
    } finally {
        // dispose the context manager to release used resources
        contextManager.dispose();
    }

    return template.buffer.toString();
}

From source file:com.ery.estorm.util.ReflectionUtils.java

/**
 * Log the current thread stacks at INFO level.
 * /*from   w  w w .ja  va2s  .c om*/
 * @param log
 *            the logger that logs the stack trace
 * @param title
 *            a descriptive title for the call stacks
 * @param minInterval
 *            the minimum time from the last
 */
public static void logThreadInfo(Log log, String title, long minInterval) {
    boolean dumpStack = false;
    if (log.isInfoEnabled()) {
        synchronized (ReflectionUtils.class) {
            long now = System.currentTimeMillis();
            if (now - previousLogTime >= minInterval * 1000) {
                previousLogTime = now;
                dumpStack = true;
            }
        }
        if (dumpStack) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            printThreadInfo(new PrintWriter(buffer), title);
            log.info(buffer.toString());
        }
    }
}

From source file:com.lenovo.tensorhusky.common.utils.ReflectionUtils.java

/**
 * Log the current thread stacks at INFO level.
 *
 * @param log         the logger that logs the stack trace
 * @param title       a descriptive title for the call stacks
 * @param minInterval the minimum time from the last
 *//*from  w  w  w  .  jav a  2  s. co  m*/
public static void logThreadInfo(Log log, String title, long minInterval) {
    boolean dumpStack = false;
    if (log.isInfoEnabled()) {
        synchronized (ReflectionUtils.class) {
            long now = clock.getTime();
            if (now - previousLogTime >= minInterval * 1000) {
                previousLogTime = now;
                dumpStack = true;
            }
        }
        if (dumpStack) {
            try {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
                log.info(buffer.toString(Charset.defaultCharset().name()));
            } catch (UnsupportedEncodingException ignored) {
            }
        }
    }
}

From source file:gridool.GridConfiguration.java

@Nonnull
private static HashFunction createHashFunction() {
    String clazz = Settings.get("gridool.hash.hasher");
    if (clazz == null) {
        String algoName = Settings.get("gridool.hash.algorithm", "sha-1");
        HashAlgorithm algo = HashAlgorithm.resolve(algoName);
        Log LOG = LogFactory.getLog(GridConfiguration.class);
        if (LOG.isInfoEnabled()) {
            LOG.info("gridool.hash.algorithm = " + algo);
        }/*from   w ww  .  jav a  2s .com*/
        return new DefaultHashFunction(algo);
    }
    Object instance = ObjectUtils.instantiate(clazz);
    if (!(instance instanceof HashFunction)) {
        throw new IllegalStateException("Hash function must be subclass of " + HashFunction.class.getName()
                + ", but was " + (instance == null ? "null" : instance.getClass().getName()));
    }
    return (HashFunction) instance;
}

From source file:com.buaa.cfs.utils.ReflectionUtils.java

/**
 * Log the current thread stacks at INFO level.
 *
 * @param log         the logger that logs the stack trace
 * @param title       a descriptive title for the call stacks
 * @param minInterval the minimum time from the last
 *//*from w  ww  .j a v a2s .c o  m*/
public static void logThreadInfo(Log log, String title, long minInterval) {
    boolean dumpStack = false;
    if (log.isInfoEnabled()) {
        synchronized (ReflectionUtils.class) {
            long now = Time.now();
            if (now - previousLogTime >= minInterval * 1000) {
                previousLogTime = now;
                dumpStack = true;
            }
        }
        if (dumpStack) {
            try {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
                log.info(buffer.toString(Charset.defaultCharset().name()));
            } catch (UnsupportedEncodingException ignored) {
            }
        }
    }
}

From source file:com.espertech.esper.epl.lookup.SubordinateQueryPlannerUtil.java

public static void queryPlanLogOnExpr(boolean queryPlanLogging, Log queryPlanLog,
        SubordinateWMatchExprQueryPlanResult strategy, Annotation[] annotations) {
    QueryPlanIndexHook hook = QueryPlanIndexHookUtil.getHook(annotations);
    if (queryPlanLogging && (queryPlanLog.isInfoEnabled() || hook != null)) {
        String prefix = "On-Expr ";
        queryPlanLog.info(prefix + "strategy " + strategy.getFactory().toQueryPlan());
        if (strategy.getIndexDescs() == null) {
            queryPlanLog.info(prefix + "full table scan");
        } else {/*from www. java2s .  c  o m*/
            for (int i = 0; i < strategy.getIndexDescs().length; i++) {
                String indexName = strategy.getIndexDescs()[i].getIndexName();
                String indexText = indexName != null ? "index " + indexName + " " : "(implicit) (" + i + ")";
                queryPlanLog.info(prefix + indexText);
            }
        }
        if (hook != null) {
            IndexNameAndDescPair[] pairs = getPairs(strategy.getIndexDescs());
            SubordTableLookupStrategyFactory inner = strategy.getFactory().getOptionalInnerStrategy();
            hook.infraOnExpr(
                    new QueryPlanIndexDescOnExpr(pairs, strategy.getFactory().getClass().getSimpleName(),
                            inner == null ? null : inner.getClass().getSimpleName()));
        }
    }
}

From source file:com.espertech.esper.epl.lookup.SubordinateQueryPlannerUtil.java

public static void queryPlanLogOnSubq(boolean queryPlanLogging, Log queryPlanLog, SubordinateQueryPlanDesc plan,
        int subqueryNum, Annotation[] annotations) {
    QueryPlanIndexHook hook = QueryPlanIndexHookUtil.getHook(annotations);
    if (queryPlanLogging && (queryPlanLog.isInfoEnabled() || hook != null)) {
        String prefix = "Subquery " + subqueryNum + " ";
        String strategy = (plan == null || plan.getLookupStrategyFactory() == null) ? "table scan"
                : plan.getLookupStrategyFactory().toQueryPlan();
        queryPlanLog.info(prefix + "strategy " + strategy);
        if (plan != null) {
            if (plan.getIndexDescs() != null) {
                for (int i = 0; i < plan.getIndexDescs().length; i++) {
                    String indexName = plan.getIndexDescs()[i].getIndexName();
                    String indexText = indexName != null ? "index " + indexName + " " : "(implicit) ";
                    queryPlanLog.info(prefix + "shared index");
                    queryPlanLog.info(prefix + indexText);
                }//from   ww  w .j av  a2 s .  c  om
            }
        }
        if (hook != null) {
            IndexNameAndDescPair[] pairs = plan == null ? new IndexNameAndDescPair[0]
                    : getPairs(plan.getIndexDescs());
            String factory = plan == null ? null : plan.getLookupStrategyFactory().getClass().getSimpleName();
            hook.subquery(new QueryPlanIndexDescSubquery(pairs, subqueryNum, factory));
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils.java

private static boolean isLevelEnabled(Log log, String level) {
    if ("fatal".equalsIgnoreCase(level)) {
        return log.isFatalEnabled();
    } else if ("error".equalsIgnoreCase(level)) {
        return log.isErrorEnabled();
    } else if ("warn".equalsIgnoreCase(level)) {
        return log.isWarnEnabled();
    } else if ("info".equalsIgnoreCase(level)) {
        return log.isInfoEnabled();
    } else if ("debug".equalsIgnoreCase(level)) {
        return log.isDebugEnabled();
    } else {/*from   w  w w.j av a 2  s  .c o  m*/
        return log.isTraceEnabled();
    }
}

From source file:net.sf.nmedit.nomad.core.jpf.JPFServiceInstallerTool.java

private static void activateService(Log log, Map<String, Class<Service>> serviceClassCache, Extension extension,
        ClassLoader pluginClassLoader) {
    String serviceClassName = extension.getParameter(SERVICE_CLASS_KEY).valueAsString();

    String implementationClassName = extension.getParameter(SERVICE_IMPLEMENTATION_CLASS_KEY).valueAsString();

    if (log.isInfoEnabled()) {
        String description = extension.getParameter(SERVICE_DESCRIPTION_KEY).valueAsString();

        log.info("Service implementation / Service: " + implementationClassName + " (description=" + description
                + ") / " + serviceClassName);
    }/*from   w  ww.j a v a 2 s  .  co  m*/

    Class<Service> serviceClass;
    try {
        serviceClass = lookupServiceClass(serviceClassCache, serviceClassName, pluginClassLoader);
    } catch (ClassNotFoundException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error loading service class: " + serviceClassName, e);
        }

        return;
    }

    Class<Service> serviceImplementationClass;
    try {
        serviceImplementationClass = lookupServiceImplementationClass(serviceClass, implementationClassName,
                pluginClassLoader);
    } catch (ClassNotFoundException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error loading service implementation class: " + implementationClassName, e);
        }
        return;
    }

    Service serviceInstance;
    try {
        serviceInstance = serviceImplementationClass.newInstance();
    } catch (InstantiationException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error instantiating service: " + serviceImplementationClass, e);
        }

        return;
    } catch (IllegalAccessException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error instantiating service: " + serviceImplementationClass, e);
        }

        return;
    }

    try {
        ServiceRegistry.addService(serviceClass, serviceInstance);
    } catch (ServiceException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error installing service: " + serviceInstance, e);
        }

        return;
    }
}

From source file:com.wavemaker.runtime.data.util.JDBCUtils.java

public static Object runSql(String sql[], String url, String username, String password, String driverClassName,
        Log logger, boolean isDDL) {

    Connection con = getConnection(url, username, password, driverClassName);

    try {//from w  ww .j a v  a  2 s  .  co  m
        try {
            con.setAutoCommit(true);
        } catch (SQLException ex) {
            throw new DataServiceRuntimeException(ex);
        }

        Statement s = con.createStatement();

        try {
            try {
                for (String stmt : sql) {
                    if (logger != null && logger.isInfoEnabled()) {
                        logger.info("Running " + stmt);
                    }
                    s.execute(stmt);
                }
                if (!isDDL) {
                    ResultSet r = s.getResultSet();
                    List<Object> rtn = new ArrayList<Object>();
                    while (r.next()) {
                        // getting only the first col is pretty unuseful
                        rtn.add(r.getObject(1));
                    }
                    return rtn.toArray(new Object[rtn.size()]);
                }
            } catch (Exception ex) {
                if (logger != null && logger.isErrorEnabled()) {
                    logger.error(ex.getMessage());
                }
                throw ex;
            }
        } finally {
            try {
                s.close();
            } catch (Exception ignore) {
            }
        }
    } catch (Exception ex) {
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        } else {
            throw new DataServiceRuntimeException(ex);
        }
    } finally {
        try {
            con.close();
        } catch (Exception ignore) {
        }
    }

    return null;
}