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

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

Introduction

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

Prototype

void info(Object message);

Source Link

Document

Logs a message with info log level.

Usage

From source file:org.springframework.boot.logging.LoggingApplicationListenerTests.java

@Test
public void addLogPathProperty() {
    EnvironmentTestUtils.addEnvironment(this.context, "logging.config: classpath:logback-nondefault.xml",
            "logging.path: target/foo/");
    this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
    logger.info("Hello world");
    String output = this.outputCapture.toString().trim();
    assertTrue("Wrong output:\n" + output, output.startsWith("target/foo/spring.log"));
}

From source file:org.springframework.boot.SpringApplication.java

/**
 * Called to log active profile information.
 * @param context the application context
 *//*from  w  ww  . j a va 2s  . c o m*/
protected void logStartupProfileInfo(ConfigurableApplicationContext context) {
    Log log = getApplicationLog();
    if (log.isInfoEnabled()) {
        String[] activeProfiles = context.getEnvironment().getActiveProfiles();
        if (ObjectUtils.isEmpty(activeProfiles)) {
            log.info("No profiles are active");
        } else {
            log.info("The following profiles are active: "
                    + StringUtils.arrayToCommaDelimitedString(activeProfiles));
        }
    }
}

From source file:org.springframework.boot.SpringApplicationBannerPrinter.java

public Banner print(Environment environment, Class<?> sourceClass, Log logger) {
    Banner banner = getBanner(environment, this.fallbackBanner);
    try {// w  w w . j  ava  2s  .  c  o m
        logger.info(createStringFromBanner(banner, environment, sourceClass));
    } catch (UnsupportedEncodingException ex) {
        logger.warn("Failed to create String for banner", ex);
    }
    return new PrintedBanner(banner, sourceClass);
}

From source file:org.springframework.boot.StartupInfoLogger.java

public void logStarting(Log log) {
    Assert.notNull(log, "Log must not be null");
    if (log.isInfoEnabled()) {
        log.info(getStartupMessage());
    }/*from   w w w  .  j  a  va2 s  . c  o m*/
    if (log.isDebugEnabled()) {
        log.debug(getRunningMessage());
    }
}

From source file:org.springframework.boot.StartupInfoLogger.java

public void logStarted(Log log, StopWatch stopWatch) {
    if (log.isInfoEnabled()) {
        log.info(getStartedMessage(stopWatch));
    }
}

From source file:org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.java

/**
 * Prepare the {@link WebApplicationContext} with the given fully loaded
 * {@link ServletContext}. This method is usually called from
 * {@link ServletContextInitializer#onStartup(ServletContext)} and is similar to the
 * functionality usually provided by a {@link ContextLoaderListener}.
 * @param servletContext the operational servlet context
 *//*from   w  w  w. j  a v  a  2  s  .co m*/
protected void prepareWebApplicationContext(ServletContext servletContext) {
    Object rootContext = servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (rootContext != null) {
        if (rootContext == this) {
            throw new IllegalStateException(
                    "Cannot initialize context because there is already a root application context present - "
                            + "check whether you have multiple ServletContextInitializers!");
        }
        return;
    }
    Log logger = LogFactory.getLog(ContextLoader.class);
    servletContext.log("Initializing Spring embedded WebApplicationContext");
    try {
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this);
        if (logger.isDebugEnabled()) {
            logger.debug("Published root WebApplicationContext as ServletContext attribute with name ["
                    + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        setServletContext(servletContext);
        if (logger.isInfoEnabled()) {
            long elapsedTime = System.currentTimeMillis() - getStartupDate();
            logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
        }
    } catch (RuntimeException | Error ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    }
}

From source file:org.springframework.core.annotation.AnnotationUtils.java

/**
 * Handle the supplied annotation introspection exception.
 * <p>If the supplied exception is an {@link AnnotationConfigurationException},
 * it will simply be thrown, allowing it to propagate to the caller, and
 * nothing will be logged./*from  ww  w  .j a  v a 2 s  . c o m*/
 * <p>Otherwise, this method logs an introspection failure (in particular
 * {@code TypeNotPresentExceptions}) before moving on, assuming nested
 * Class values were not resolvable within annotation attributes and
 * thereby effectively pretending there were no annotations on the specified
 * element.
 * @param element the element that we tried to introspect annotations on
 * @param ex the exception that we encountered
 * @see #rethrowAnnotationConfigurationException
 */
static void handleIntrospectionFailure(@Nullable AnnotatedElement element, Throwable ex) {
    rethrowAnnotationConfigurationException(ex);

    Log loggerToUse = logger;
    if (loggerToUse == null) {
        loggerToUse = LogFactory.getLog(AnnotationUtils.class);
        logger = loggerToUse;
    }
    if (element instanceof Class && Annotation.class.isAssignableFrom((Class<?>) element)) {
        // Meta-annotation or (default) value lookup on an annotation type
        if (loggerToUse.isDebugEnabled()) {
            loggerToUse.debug("Failed to meta-introspect annotation [" + element + "]: " + ex);
        }
    } else {
        // Direct annotation lookup on regular Class, Method, Field
        if (loggerToUse.isInfoEnabled()) {
            loggerToUse.info("Failed to introspect annotations on [" + element + "]: " + ex);
        }
    }
}

From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java

/**
 * Constructs a new <code>ExtenderConfiguration</code> instance. Locates the extender configuration, creates an
 * application context which will returned the extender items.
 * /* www  . j a va2  s  .  c om*/
 * @param bundleContext extender OSGi bundle context
 */
public ExtenderConfiguration(BundleContext bundleContext, Log log) {
    this.log = log;
    Bundle bundle = bundleContext.getBundle();
    Properties properties = new Properties(createDefaultProperties());

    Enumeration<?> enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false);

    if (enm == null) {
        log.info("No custom extender configuration detected; using defaults...");

        synchronized (lock) {
            taskExecutor = createDefaultTaskExecutor();
            shutdownTaskExecutor = createDefaultShutdownTaskExecutor();
            eventMulticaster = createDefaultEventMulticaster();
            contextCreator = createDefaultApplicationContextCreator();
            contextEventListener = createDefaultApplicationContextListener();

        }
        classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle);
    } else {
        String[] configs = copyEnumerationToList(enm);

        log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs));
        // create OSGi specific XML context
        ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs);
        extenderAppCtx.setBundleContext(bundleContext);
        extenderAppCtx.refresh();

        synchronized (lock) {
            extenderConfiguration = extenderAppCtx;
            // initialize beans
            taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME)
                    ? (TaskExecutor) extenderConfiguration.getBean(TASK_EXECUTOR_NAME, TaskExecutor.class)
                    : createDefaultTaskExecutor();

            shutdownTaskExecutor = extenderConfiguration.containsBean(SHUTDOWN_TASK_EXECUTOR_NAME)
                    ? (TaskExecutor) extenderConfiguration.getBean(SHUTDOWN_TASK_EXECUTOR_NAME,
                            TaskExecutor.class)
                    : createDefaultShutdownTaskExecutor();

            eventMulticaster = extenderConfiguration.containsBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
                    ? (OsgiBundleApplicationContextEventMulticaster) extenderConfiguration.getBean(
                            APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
                            OsgiBundleApplicationContextEventMulticaster.class)
                    : createDefaultEventMulticaster();

            contextCreator = extenderConfiguration.containsBean(CONTEXT_CREATOR_NAME)
                    ? (OsgiApplicationContextCreator) extenderConfiguration.getBean(CONTEXT_CREATOR_NAME,
                            OsgiApplicationContextCreator.class)
                    : createDefaultApplicationContextCreator();

            contextEventListener = extenderConfiguration.containsBean(CONTEXT_LISTENER_NAME)
                    ? (OsgiBundleApplicationContextListener) extenderConfiguration
                            .getBean(CONTEXT_LISTENER_NAME, OsgiBundleApplicationContextListener.class)
                    : createDefaultApplicationContextListener();
        }

        // get post processors
        postProcessors
                .addAll(extenderConfiguration.getBeansOfType(OsgiBeanFactoryPostProcessor.class).values());

        // get dependency factories
        dependencyFactories
                .addAll(extenderConfiguration.getBeansOfType(OsgiServiceDependencyFactory.class).values());

        classLoader = extenderConfiguration.getClassLoader();
        // extender properties using the defaults as backup
        if (extenderConfiguration.containsBean(PROPERTIES_NAME)) {
            Properties customProperties = (Properties) extenderConfiguration.getBean(PROPERTIES_NAME,
                    Properties.class);
            Enumeration<?> propertyKey = customProperties.propertyNames();
            while (propertyKey.hasMoreElements()) {
                String property = (String) propertyKey.nextElement();
                properties.setProperty(property, customProperties.getProperty(property));
            }
        }
    }

    synchronized (lock) {
        shutdownWaitTime = getShutdownWaitTime(properties);
        dependencyWaitTime = getDependencyWaitTime(properties);
        processAnnotation = getProcessAnnotations(properties);
    }

    // load default dependency factories
    addDefaultDependencyFactories();

    // allow post processing
    contextCreator = postProcess(contextCreator);
}

From source file:org.springframework.util.Log4jConfigurerTests.java

private void doTestInitLogging(String location, boolean refreshInterval) throws FileNotFoundException {
    if (refreshInterval) {
        Log4jConfigurer.initLogging(location, 10);
    } else {/*from   w ww.j av  a 2s.  c  om*/
        Log4jConfigurer.initLogging(location);
    }

    Log log = LogFactory.getLog(this.getClass());
    log.debug("debug");
    log.info("info");
    log.warn("warn");
    log.error("error");
    log.fatal("fatal");

    assertTrue(MockLog4jAppender.loggingStrings.contains("debug"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("info"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("warn"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("error"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("fatal"));

    Log4jConfigurer.shutdownLogging();
    assertTrue(MockLog4jAppender.closeCalled);
}

From source file:org.springframework.util.Log4jConfigurerTestSuite.java

public void testInitLoggingString() throws FileNotFoundException {
    try {/*from ww w.ja  va 2 s .  c o  m*/
        Log4jConfigurer.initLogging("test/org/springframework/util/bla.properties");
        fail("Exception should have been thrown, file does not exist!");
    } catch (FileNotFoundException e) {
        // ok
    }

    Log4jConfigurer.initLogging("test/org/springframework/util/testlog4j.properties");

    Log log = LogFactory.getLog(this.getClass());
    log.debug("debug");
    log.info("info");
    log.warn("warn");
    log.error("error");
    log.fatal("fatal");

    assertTrue(MockLog4jAppender.loggingStrings.contains("debug"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("info"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("warn"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("error"));
    assertTrue(MockLog4jAppender.loggingStrings.contains("fatal"));
}