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.dhcc.framework.web.context.DhccContextLoader.java

/**
 * Initialize Spring's web application context for the given servlet 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 servletContext current servlet context
 * @return the new WebApplicationContext
 * @see #ContextLoader(WebApplicationContext)
 * @see #CONTEXT_CLASS_PARAM/*ww w . j  a va 2  s .  c o m*/
 * @see #CONFIG_LOCATION_PARAM
 */
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
    if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException(
                "Cannot initialize context because there is already a root application context present - "
                        + "check whether you have multiple ContextLoader* definitions in your web.xml!");
    }

    Log logger = LogFactory.getLog(DhccContextLoader.class);
    servletContext.log("Initializing Spring root WebApplicationContext");
    if (logger.isInfoEnabled()) {
        logger.info("Root WebApplicationContext: initialization started");
    }
    long startTime = System.currentTimeMillis();

    try {
        // Store context in local instance variable, to guarantee that
        // it is available on ServletContext shutdown.
        if (this.context == null) {
            this.context = createWebApplicationContext(servletContext);
        }
        if (this.context instanceof ConfigurableWebApplicationContext) {
            ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
            if (!cwac.isActive()) {
                // The context has not yet been refreshed -> provide services such as
                // setting the parent context, setting the application context id, etc
                if (cwac.getParent() == null) {
                    // The context instance was injected without an explicit parent ->
                    // determine parent for root web application context, if any.
                    ApplicationContext parent = loadParentContext(servletContext);
                    cwac.setParent(parent);
                }
                configureAndRefreshWebApplicationContext(cwac, servletContext);
            }
        }
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

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

        if (logger.isDebugEnabled()) {
            logger.debug("Published root WebApplicationContext as ServletContext attribute with name ["
                    + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        if (logger.isInfoEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
        }

        return this.context;
    } catch (RuntimeException ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error err) {
        logger.error("Context initialization failed", err);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
        throw err;
    }
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Adds (installs) a new hot bean module.
 *//*from  w  w w  .  j a va  2 s  . c om*/
public HotBeanModuleInfo addHotBeanModule(final InputStream moduleFile) {
    Log logger = this.getLog();

    if (logger.isInfoEnabled())
        logger.info("Attempting to add module.");

    HotBeanModuleInfo hotBeanModuleInfo = this.updateModuleInternal(null, moduleFile, true);

    if (logger.isInfoEnabled())
        logger.info("Done adding module - " + hotBeanModuleInfo + ".");

    if (hotBeanModuleInfo != null)
        return hotBeanModuleInfo.getClone();
    else
        return hotBeanModuleInfo;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Updates an existing hot beans module with a new revision.
 */// w  w  w .  j  a  va 2 s  .  c  o  m
public HotBeanModuleInfo updateHotBeanModule(final String moduleName, final InputStream moduleFile) {
    Log logger = this.getLog();

    if (logger.isInfoEnabled())
        logger.info("Attempting to update module '" + moduleName + "'.");

    HotBeanModuleInfo hotBeanModuleInfo = this.updateModuleInternal(moduleName, moduleFile, false);

    if (logger.isInfoEnabled())
        logger.info("Done updating module - " + hotBeanModuleInfo + ".");

    if (hotBeanModuleInfo != null)
        return hotBeanModuleInfo.getClone();
    else
        return hotBeanModuleInfo;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Registers an unloaded (history) module.
 *//*from  ww w. j a  v  a 2s.c o  m*/
protected void registerHistoryModule(final String moduleName, final long revision) throws Exception {
    Log logger = this.getLog();

    if (logger.isInfoEnabled())
        logger.info("Registering unloaded module '" + moduleName + "', revision " + revision + ".");

    File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
    File moduleFile = new File(moduleDirectory, revision + MODULE_FILE_SUFFIX);

    Manifest manifest = ModuleManifestUtils.readManifest(moduleFile);
    // Get version from mainfest
    String version = ModuleManifestUtils.getVersion(manifest);
    if ((version == null) || (version.trim().length() == 0))
        version = "n/a";
    // Get description from mainfest
    String description = ModuleManifestUtils.getDescription(manifest);

    HotBeanModuleInfo hotBeanModuleInfo = new HotBeanModuleInfo(moduleName, description, revision, version,
            moduleFile.lastModified());
    HotBeanModule hotBeanModue = super.createHotBeanModule(hotBeanModuleInfo);

    // Register HotBeanModule
    super.registerHotBeanModule(hotBeanModue);

    if (logger.isInfoEnabled())
        logger.info("Unloaded module '" + moduleName + "', revision " + revision + " registered.");
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Removes all revisions of a hot bean module.
 */// w w w.  ja  v a2 s  .c  o m
public void removeHotBeanModule(final String moduleName) {
    Log logger = this.getLog();

    if (logger.isInfoEnabled())
        logger.info("Removing module '" + moduleName + "'.");

    synchronized (super.getLock()) {
        RepositoryFileLock fileLock = null;
        try {
            HotBeanModuleType moduleType = super.getHotBeanModuleType(moduleName);

            if (moduleType != null) {
                // Mark current module revision as as deleted to indicate that the module should be deleted
                moduleType.setRemoveType(true);

                fileLock = this.obtainRepositoryFileLock(false); // Obtain lock

                File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
                FileDeletor.delete(moduleDirectory);

                this.checkForObsoleteModules(moduleName); // Perform a check on the module at once, to make sure it is
                                                          // removed
            }
        } catch (Exception e) {
            logger.error("Error deleting module '" + moduleName + " - " + e + "'!", e);
            throw new HotBeansException("Error deleting module '" + moduleName + " - " + e + "'!");
        } finally {
            this.releaseRepositoryFileLock(fileLock);
            fileLock = null;
        }
    }
}

From source file:com.amazon.carbonado.repo.indexed.ManagedIndex.java

private long logProgress(long nextReportTime, Log log, long totalProgress, int bufferSize, long totalInserted,
        long totalUpdated, long totalDeleted) {
    long now = System.currentTimeMillis();
    if (now >= nextReportTime) {
        if (log.isInfoEnabled()) {
            String format = "Index build progress: %.3f%% "
                    + progressSubMessgage(totalInserted, totalUpdated, totalDeleted);
            double percent = 100.0 * totalProgress / bufferSize;
            log.info(String.format(format, percent));
        }//from  ww  w. j ava  2s .co  m
        nextReportTime = now + BUILD_INFO_DELAY_MILLIS;
    }
    return nextReportTime;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Loads a module./*  w w  w  .  j  av a 2  s  . c  om*/
 */
protected HotBeanModuleInfo loadModule(final String moduleName, final long revision) throws Exception {
    Log logger = this.getLog();
    if (logger.isInfoEnabled())
        logger.info("Loading module '" + moduleName + "', revision " + revision + ".");

    File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
    File moduleFile = new File(moduleDirectory, revision + MODULE_FILE_SUFFIX);
    File tempDir = new File(this.temporaryDirectory, moduleName + "." + revision);

    Manifest manifest = ModuleManifestUtils.readManifest(moduleFile);
    // Get version from mainfest
    String version = ModuleManifestUtils.getVersion(manifest);
    if ((version == null) || (version.trim().length() == 0))
        version = "n/a";
    // Get description from mainfest
    String description = ModuleManifestUtils.getDescription(manifest);

    HotBeanModuleInfo hotBeanModuleInfo = new HotBeanModuleInfo(moduleName, description, revision, version,
            moduleFile.lastModified());

    HotBeanModuleLoader hotBeanModuleLoader = null;
    HotBeanContext hotBeanContext = null;
    String errorReason = null;

    HotBeanModule hotBeanModule = null;

    try {
        // Create loader
        hotBeanModuleLoader = super.createHotBeanModuleLoader(moduleFile, tempDir);

        // Create context
        hotBeanContext = super.createHotBeanContext(this, manifest, hotBeanModuleLoader.getClassLoader());

        if ((hotBeanContext instanceof ConfigurableApplicationContext)
                && (this.parentApplicationContext != null)) {
            if (logger.isInfoEnabled())
                logger.info("Setting parent Spring ApplicationContext for HotBeanContext(" + hotBeanContext
                        + ") of module '" + moduleName + "', revision " + revision + ".");
            ((ConfigurableApplicationContext) hotBeanContext).setParent(this.parentApplicationContext);
        }

        // Initialize context
        hotBeanContext.init();

        // Create module
        hotBeanModule = super.createHotBeanModule(hotBeanModuleInfo, hotBeanModuleLoader, hotBeanContext);

        // Init loader
        hotBeanModuleLoader.init(hotBeanModule);
    } catch (Exception e) {
        hotBeanModuleLoader = null;
        hotBeanContext = null;
        hotBeanModule = null;
        errorReason = e.getMessage();
        logger.error(
                "Error loading module '" + moduleName + "', revision " + revision + " - " + errorReason + "!",
                e);
    }

    if (hotBeanModule == null) {
        hotBeanModule = super.createHotBeanModule(hotBeanModuleInfo);
        hotBeanModule.setError(errorReason);
    }

    // Register HotBeanModule
    super.registerHotBeanModule(hotBeanModule);

    if ((hotBeanContext != null) && logger.isInfoEnabled())
        logger.info("Module '" + moduleName + "', revision " + revision + " loaded.");

    return hotBeanModuleInfo;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Reverts an hot beans module to a previous revision (which becomes a new revision).
 *///from   w  w w.jav  a2  s. c o  m
public HotBeanModuleInfo revertHotBeanModule(final String moduleName, final long revision) {
    Log logger = this.getLog();
    HotBeanModuleInfo hotBeanModuleInfo = null;

    if (logger.isInfoEnabled())
        logger.info("Attempting to revert module '" + moduleName + "' to revision " + revision + ".");

    synchronized (super.getLock()) {
        File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
        File moduleFile = new File(moduleDirectory, revision + MODULE_FILE_SUFFIX);

        if (moduleFile.exists()) {
            try {
                hotBeanModuleInfo = this.updateModuleInternal(moduleName, new FileInputStream(moduleFile),
                        false);

                if (logger.isInfoEnabled())
                    logger.info("Done reverting module - " + hotBeanModuleInfo + ".");
            } catch (Exception e) {
                logger.error("Error reverting module '" + moduleName + " - " + e + "'!", e);
                throw new HotBeansException("Error reverting module '" + moduleName + " - " + e + "'!");
            }
        } else
            throw new HotBeansException(
                    "Revision " + revision + " doesn't exist for module '" + moduleName + "!");
    }

    if (hotBeanModuleInfo != null)
        return hotBeanModuleInfo.getClone();
    else
        return hotBeanModuleInfo;
}

From source file:com.flexive.shared.exceptions.FxApplicationException.java

/**
 * Log a message at a given level (or error if no level given)
 *
 * @param log     Log to use//from w  ww  .  j  a v  a 2s .  c  om
 * @param message message to LOG
 * @param level   log4j level to apply
 */
private void logMessage(Log log, String message, LogLevel level) {
    this.messageLogged = true;
    if (FxContext.get() != null && FxContext.get().isTestDivision())
        return; //dont log exception traces during automated tests
    final Throwable cause = getCause() != null ? getCause() : this;
    if (level == null)
        log.error(message, cause);
    else {
        switch (level) {
        case DEBUG:
            if (log.isDebugEnabled())
                log.debug(message);
            break;
        case ERROR:
            if (log.isErrorEnabled())
                log.error(message, cause);
            break;
        case FATAL:
            if (log.isFatalEnabled())
                log.fatal(message, cause);
            break;
        case INFO:
            if (log.isInfoEnabled())
                log.info(message);
            break;
        //                case Level.WARN_INT:
        default:
            if (log.isWarnEnabled())
                log.warn(message);
        }
    }
}

From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfig.java

public void afterPropertiesSet() {
    final Log log;
    final ListableBeanFactory beanFactory;
    final String[] beanNames;
    final List<RemoteServiceConfig> serviceConfigs;

    log = LogFactory.getLog(AutowiredRemoteServiceGroupConfig.class);
    log.debug("Searching for remote services");

    beanFactory = getApplicationContext();
    beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RemoteService.class, true,
            false);/*from   w w  w  . ja v  a 2  s.c o  m*/
    if (beanNames.length == 0) {
        return;
    }

    serviceConfigs = new ArrayList<RemoteServiceConfig>();
    for (String beanName : beanNames) {
        final Class<?> beanType;
        final Class<?> serviceInterface;

        beanType = beanFactory.getType(beanName);
        serviceInterface = getRemoteServiceInterface(beanType);
        if (serviceInterface != null) {
            if (serviceInterface.getAnnotation(RemoteServiceRelativePath.class) != null) {
                if (isAcceptedServiceInterface(serviceInterface)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Adding service '" + beanName + "'");
                    }
                    serviceConfigs.add(new RemoteServiceConfig(beanName));
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Ignoring service '" + beanName + "' since service does not specify "
                            + "remote service relative path");
                }
            }
        } else {
            if (log.isInfoEnabled()) {
                log.info("Ignoring service '" + beanName + "' since it implements multiple "
                        + "remote service interfaces");
            }
        }
    }

    setServiceConfigs(serviceConfigs);
}