List of usage examples for org.apache.commons.logging Log error
void error(Object message, Throwable t);
From source file:org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.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 *//* w w w . j a va2 s . c o m*/ protected void prepareEmbeddedWebApplicationContext(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 ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } catch (Error ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } }
From source file:org.springframework.boot.legacy.context.web.NonEmbeddedWebApplicationContext.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 . ja v a 2 s . c o 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!"); } else { return; } } Log logger = LogFactory.getLog(ContextLoader.class); servletContext.log("Initializing Spring embedded WebApplicationContext"); WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(), getServletContext()); WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), getServletContext()); 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 + "]"); } if (logger.isInfoEnabled()) { long elapsedTime = System.currentTimeMillis() - getStartupDate(); logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms"); } } catch (RuntimeException ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } catch (Error ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } }
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 *//* w w w . jav a 2 s . c o 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.flex.core.CommonsLoggingTarget.java
public void logEvent(LogEvent logevent) { String category = logevent.logger.getCategory(); if (this.categoryPrefix != null) { category = this.categoryPrefix + "." + category; }/*from w w w .j a va 2 s. co m*/ Log log = LogFactory.getLog(category); switch (logevent.level) { case LogEvent.FATAL: if (log.isFatalEnabled()) { log.fatal(logevent.message, logevent.throwable); } break; case LogEvent.ERROR: if (log.isErrorEnabled()) { log.error(logevent.message, logevent.throwable); } break; case LogEvent.WARN: if (log.isWarnEnabled()) { log.warn(logevent.message, logevent.throwable); } break; case LogEvent.INFO: if (log.isInfoEnabled()) { log.info(logevent.message, logevent.throwable); } break; case LogEvent.DEBUG: if (log.isDebugEnabled()) { log.debug(logevent.message, logevent.throwable); } break; case LogEvent.ALL: if (log.isTraceEnabled()) { log.trace(logevent.message, logevent.throwable); } break; default: break; } }
From source file:org.springframework.kafka.listener.FailedRecordTracker.java
FailedRecordTracker(@Nullable BiConsumer<ConsumerRecord<?, ?>, Exception> recoverer, int maxFailures, Log logger) { if (recoverer == null) { this.recoverer = (r, t) -> logger.error("Max failures (" + maxFailures + ") reached for: " + r, t); } else {/* w w w . ja v a2s . c o m*/ this.recoverer = recoverer; } this.maxFailures = maxFailures; }
From source file:org.springframework.kafka.support.SeekUtils.java
/** * Seek records to earliest position, optionally skipping the first. * @param records the records./*from w ww . ja va 2s .c o m*/ * @param consumer the consumer. * @param exception the exception * @param recoverable true if skipping the first record is allowed. * @param skipper function to determine whether or not to skip seeking the first. * @param logger a {@link Log} for seek errors. * @return true if the failed record was skipped. */ public static boolean doSeeks(List<ConsumerRecord<?, ?>> records, Consumer<?, ?> consumer, Exception exception, boolean recoverable, BiPredicate<ConsumerRecord<?, ?>, Exception> skipper, Log logger) { Map<TopicPartition, Long> partitions = new LinkedHashMap<>(); AtomicBoolean first = new AtomicBoolean(true); AtomicBoolean skipped = new AtomicBoolean(); records.forEach(record -> { if (recoverable && first.get()) { skipped.set(skipper.test(record, exception)); if (skipped.get() && logger.isDebugEnabled()) { logger.debug("Skipping seek of: " + record); } } if (!recoverable || !first.get() || !skipped.get()) { partitions.computeIfAbsent(new TopicPartition(record.topic(), record.partition()), offset -> record.offset()); } first.set(false); }); boolean tracing = logger.isTraceEnabled(); partitions.forEach((topicPartition, offset) -> { try { if (tracing) { logger.trace("Seeking: " + topicPartition + " to: " + offset); } consumer.seek(topicPartition, offset); } catch (Exception e) { logger.error("Failed to seek " + topicPartition + " to " + offset, e); } }); return skipped.get(); }
From source file:org.springframework.orm.toplink.support.CommonsLoggingSessionLog.java
public void log(SessionLogEntry entry) { Log logger = LogFactory.getLog(getCategory(entry)); switch (entry.getLevel()) { case SEVERE:/*from w ww. j a v a 2s . c o m*/ if (logger.isErrorEnabled()) { if (entry.hasException()) { logger.error(getMessageString(entry), getException(entry)); } else { logger.error(getMessageString(entry)); } } break; case WARNING: if (logger.isWarnEnabled()) { if (entry.hasException()) { logger.warn(getMessageString(entry), getException(entry)); } else { logger.warn(getMessageString(entry)); } } break; case INFO: if (logger.isInfoEnabled()) { if (entry.hasException()) { logger.info(getMessageString(entry), getException(entry)); } else { logger.info(getMessageString(entry)); } } break; case CONFIG: case FINE: case FINER: if (logger.isDebugEnabled()) { if (entry.hasException()) { logger.debug(getMessageString(entry), getException(entry)); } else { logger.debug(getMessageString(entry)); } } break; case FINEST: if (logger.isTraceEnabled()) { if (entry.hasException()) { logger.trace(getMessageString(entry), getException(entry)); } else { logger.trace(getMessageString(entry)); } } break; } }
From source file:org.springframework.web.context.ContextLoader.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/*w ww . ja v a 2 s. c om*/ * @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(ContextLoader.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 == ContextLoader.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:org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.java
public static void tryCloseWithError(WebSocketSession session, Throwable exception, Log logger) { if (logger.isErrorEnabled()) { logger.error("Closing session due to exception for " + session, exception); }// w w w . ja v a 2s . co m if (session.isOpen()) { try { session.close(CloseStatus.SERVER_ERROR); } catch (Throwable ex) { // ignore } } }
From source file:org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator.java
public static void tryCloseWithError(WebSocketSession session, Throwable exception, Log logger) { logger.error("Closing due to exception for " + session, exception); if (session.isOpen()) { try {//w ww . ja v a 2 s. c o m session.close(CloseStatus.SERVER_ERROR); } catch (Throwable t) { // ignore } } }