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.danann.cernunnos.runtime.Main.java

public static void main(String[] args) {

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

    // Put some whitespace between the command and the output...
    System.out.println("");

    // Register custom protocol handlers...
    try {//from w w w.j  a v  a 2  s . c om
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryImpl());
    } catch (Throwable t) {
        log.warn("Cernunnos was unable to register a URLStreamHandlerFactory.  "
                + "Custom URL protocols may not work properly (e.g. classpath://, c:/).  "
                + "See stack trace below.", t);
    }

    // Establish CRN_HOME...
    String crnHome = System.getenv("CRN_HOME");
    if (crnHome == null) {
        if (log.isDebugEnabled()) {
            log.debug("The CRN_HOME environment variable is not defined;  "
                    + "this is completely normal for embedded applications " + "of Cernunnos.");
        }
    }

    // Look at the specified script:  might it be in the bin/ directory?
    String location = args[0];
    try {
        // This is how ScriptRunner will attempt to locate the script file...
        URL u = new URL(new File(".").toURI().toURL(), location);
        if (u.getProtocol().equals("file")) {
            // We know the specified resource is a local file;  is it either 
            // (1) absolute or (2) relative to the directory where Java is 
            // executing?
            if (!new File(u.toURI()).exists() && crnHome != null) {
                // No.  And what's more, 'CRN_HOME' is defined.  In this case 
                // let's see if the specified script *is* present in the bin/ 
                // directory.
                StringBuilder path = new StringBuilder();
                path.append(crnHome).append(File.separator).append("bin").append(File.separator)
                        .append(location);
                File f = new File(path.toString());
                if (f.exists()) {
                    // The user is specifying a Cernunnos script in the bin/ directory...
                    location = f.toURI().toURL().toExternalForm();
                    if (log.isInfoEnabled()) {
                        log.info("Resolving the specified Cernunnos document "
                                + "to a file in the CRN_HOME/bin directory:  " + location);
                    }
                }
            }
        }
    } catch (Throwable t) {
        // Just let this pass -- genuine issues will be caught & reported shortly...
    }

    // Analyze the command-line arguments...
    RuntimeRequestResponse req = new RuntimeRequestResponse();
    switch (args.length) {
    case 0:
        // No file provided, can't continue...
        System.out.println("Usage:\n\n\t>crn [script_name] [arguments]");
        System.exit(0);
        break;
    default:
        for (int i = 1; i < args.length; i++) {
            req.setAttribute("$" + i, args[i]);
        }
        break;
    }

    ScriptRunner runner = new ScriptRunner();
    runner.run(location, req);

}

From source file:org.displaytag.exception.BaseNestableJspTagException.java

/**
 * Instantiate a new BaseNestableJspTagException.
 * @param source Class where the exception is generated
 * @param message message/*from   w ww .jav  a 2s.c o  m*/
 */
public BaseNestableJspTagException(Class source, String message) {
    super(message);
    this.sourceClass = source;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString());
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString());
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString());
    } else {
        // error - default
        log.error(toString());
    }

}

From source file:org.displaytag.exception.BaseNestableRuntimeException.java

/**
 * Instantiate a new BaseNestableRuntimeException.
 * @param source Class where the exception is generated
 * @param message message/*w  ww.  ja  va2  s.com*/
 */
public BaseNestableRuntimeException(Class source, String message) {
    super(message);
    this.sourceClass = source;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString());
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString());
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString());
    } else {
        // error - default
        log.error(toString());
    }

}

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(", ");
        }/*from w  ww  .  j av a  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  ww. 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

/**
 * 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
 *///from   w  w w  .java 2s .  c  o  m
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.eclipse.gemini.blueprint.extender.internal.blueprint.activator.BlueprintContainerProcessor.java

public void preProcessRefresh(final ConfigurableOsgiBundleApplicationContext context) {
    final BundleContext bundleContext = context.getBundleContext();
    // create the ModuleContext adapter
    final BlueprintContainer blueprintContainer = createBlueprintContainer(context);

    // 1. add event listeners
    // add service publisher
    context.addApplicationListener(new BlueprintContainerServicePublisher(blueprintContainer, bundleContext));
    // add waiting event broadcaster
    context.addApplicationListener(new BlueprintWaitingEventDispatcher(context.getBundleContext()));

    // 2. add environmental managers
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        private static final String BLUEPRINT_BUNDLE = "blueprintBundle";
        private static final String BLUEPRINT_BUNDLE_CONTEXT = "blueprintBundleContext";
        private static final String BLUEPRINT_CONTAINER = "blueprintContainer";
        private static final String BLUEPRINT_EXTENDER = "blueprintExtenderBundle";
        private static final String BLUEPRINT_CONVERTER = "blueprintConverter";

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // lazy logger evaluation
            Log logger = LogFactory.getLog(context.getClass());

            if (!(beanFactory instanceof BeanDefinitionRegistry)) {
                logger.warn("Environmental beans will be registered as singletons instead "
                        + "of usual bean definitions since beanFactory " + beanFactory
                        + " is not a BeanDefinitionRegistry");
            }/*from  www.  jav  a  2s.com*/

            // add blueprint container bean
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_BUNDLE, bundleContext.getBundle(), logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_BUNDLE_CONTEXT, bundleContext, logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_CONTAINER, blueprintContainer, logger);
            // addPredefinedBlueprintBean(beanFactory, BLUEPRINT_EXTENDER, extenderBundle, logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_CONVERTER,
                    new SpringBlueprintConverter(beanFactory), logger);

            // add Blueprint conversion service
            // String[] beans = beanFactory.getBeanNamesForType(BlueprintConverterConfigurer.class, false, false);
            // if (ObjectUtils.isEmpty(beans)) {
            // beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
            // }
            beanFactory.setConversionService(
                    new SpringBlueprintConverterService(beanFactory.getConversionService(), beanFactory));
        }

        private void addPredefinedBlueprintBean(ConfigurableListableBeanFactory beanFactory, String beanName,
                Object value, Log logger) {
            if (!beanFactory.containsLocalBean(beanName)) {
                logger.debug("Registering pre-defined bean named " + beanName);
                if (beanFactory instanceof BeanDefinitionRegistry) {
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

                    GenericBeanDefinition def = new GenericBeanDefinition();
                    def.setBeanClass(ENV_FB_CLASS);
                    ConstructorArgumentValues cav = new ConstructorArgumentValues();
                    cav.addIndexedArgumentValue(0, value);
                    def.setConstructorArgumentValues(cav);
                    def.setLazyInit(false);
                    def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
                    registry.registerBeanDefinition(beanName, def);

                } else {
                    beanFactory.registerSingleton(beanName, value);
                }

            } else {
                logger.warn("A bean named " + beanName
                        + " already exists; aborting registration of the predefined value...");
            }
        }
    });

    // 3. add cycle breaker
    context.addBeanFactoryPostProcessor(cycleBreaker);

    BlueprintEvent creatingEvent = new BlueprintEvent(BlueprintEvent.CREATING, context.getBundle(),
            extenderBundle);
    listenerManager.blueprintEvent(creatingEvent);
    dispatcher.beforeRefresh(creatingEvent);
}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * This method adds an index entry to the data dictionary and saves it.
 * /*from   w  w  w. j av  a  2  s .c om*/
 * @param dIndex
 *          the d index
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static void addIndex(final DIndex dIndex) throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);
    synchronized (mutex) {
        ensureLoaded();
        if (hasIndexIgnoreCase(dIndex.getName())) {
            throw new DataDictionaryException(
                    "index already exists in data dictionary [" + getExistingIndexName(dIndex.getName()) + "]");
        }

        final DConfiguration dConfig = dIndex.getConfiguration();
        if (dConfig != null) {
            validateConfiguration(dConfig, dIndex.getIndexStructure());
        }

        dd.addIndex(dIndex);

        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
    }
}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * Rename index./*w  ww  . j ava2s  .c  o m*/
 * 
 * @param indexName
 *          the index name
 * @param newIndexName
 *          the new index name
 * 
 * @return true, if successful
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static boolean renameIndex(final String indexName, final String newIndexName)
        throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);

    synchronized (mutex) {
        ensureLoaded();
        if (dd.getIndex(newIndexName) != null) {
            throw new DataDictionaryException(
                    String.format("Cannot rename index to [%s] because it's already exists!", newIndexName));
        }
        log.debug("Updating datadictionary...");
        final DIndex index = dd.getIndex(indexName);
        if (index == null) {
            return false; // no index entry
        }
        dd.removeIndex(index);
        index.setName(newIndexName);
        final DIndexStructure indexStructure = index.getIndexStructure();
        if (indexStructure != null) {
            indexStructure.setName(newIndexName);
        }
        dd.addIndex(index);
        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
        return true;
    }

}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * This method removes an index entry from the data dictionary. It returnes true, when the index entry has exists.
 * /*  ww w.ja va2  s .c o  m*/
 * @param indexName
 *          the index name
 * 
 * @return true, if delete index
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static boolean deleteIndex(final String indexName) throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);

    synchronized (mutex) {
        ensureLoaded();
        log.debug("Updating datadictionary...");
        final DIndex index = dd.getIndex(indexName);
        if (index == null) {
            return false; // no index entry
        }
        dd.removeIndex(index);

        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
        return true;
    }
}