private static void traceMatch(String prefix, Object desired, @Nullable Object actual, boolean match) { if (logger.isTraceEnabled()) { logger.trace(String.format("%s \"%s\" %s against value \"%s\"", prefix, desired, match ? "matches" : "does not match", actual)); } }
/** * Invoked after all handler methods have been detected. * @param handlerMethods a read-only map with handler methods and mappings. */ protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) { // Total includes detected mappings + explicit registrations via registerMapping int total = handlerMethods.size(); if ((logger.isTraceEnabled() && total == 0) || (logger.isDebugEnabled() && total > 0) ) { logger.debug(total + " mappings in " + formatMappingName()); } }
@Override public void setServletContext(ServletContext servletContext) { if (this.attributes != null) { for (Map.Entry<String, Object> entry : this.attributes.entrySet()) { String attributeName = entry.getKey(); if (logger.isDebugEnabled()) { if (servletContext.getAttribute(attributeName) != null) { logger.debug("Replacing existing ServletContext attribute with name '" + attributeName + "'"); } } servletContext.setAttribute(attributeName, entry.getValue()); if (logger.isTraceEnabled()) { logger.trace("Exported ServletContext attribute with name '" + attributeName + "'"); } } } }
@Override public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException { BeanDefinition bd = this.beanDefinitionMap.get(beanName); if (bd == null) { if (logger.isTraceEnabled()) { logger.trace("No bean named '" + beanName + "' found in " + this); } throw new NoSuchBeanDefinitionException(beanName); } return bd; }
BufferingStompDecoder decoder = this.decoders.get(session.getId()); if (decoder == null) { throw new IllegalStateException("No decoder for session id '" + session.getId() + "'"); if (logger.isTraceEnabled()) { logger.trace("Incomplete STOMP frame content received in session " + session + ", bufferSize=" + decoder.getBufferSize() + ", bufferSizeLimit=" + decoder.getBufferSizeLimit() + "."); logger.error("Failed to parse " + webSocketMessage + " in session " + session.getId() + ". Sending STOMP ERROR to client.", ex); if (logger.isTraceEnabled()) { logger.trace("From client: " + headerAccessor.getShortLogMessage(message.getPayload())); logger.error("Failed to send client message to application via MessageChannel" + " in session " + session.getId() + ". Sending STOMP ERROR to client.", ex);
@Override public void executeSendRequest(URI url, HttpHeaders headers, TextMessage message) { if (logger.isTraceEnabled()) { logger.trace("Starting XHR send, url=" + url); } ResponseEntity<String> response = executeSendRequestInternal(url, headers, message); if (response.getStatusCode() != HttpStatus.NO_CONTENT) { if (logger.isErrorEnabled()) { logger.error("XHR send request (url=" + url + ") failed: " + response); } throw new HttpServerErrorException(response.getStatusCode()); } if (logger.isTraceEnabled()) { logger.trace("XHR send request (url=" + url + ") response: " + response); } }
protected int update(final PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss) throws DataAccessException { logger.debug("Executing prepared SQL update"); return updateCount(execute(psc, ps -> { try { if (pss != null) { pss.setValues(ps); } int rows = ps.executeUpdate(); if (logger.isTraceEnabled()) { logger.trace("SQL update affected " + rows + " rows"); } return rows; } finally { if (pss instanceof ParameterDisposer) { ((ParameterDisposer) pss).cleanupParameters(); } } })); }
@Override public void close() { if (log.isTraceEnabled()) { log.trace("Closing HTTP transport to " + httpInfo); } HttpConnectionManager manager = client.getHttpConnectionManager(); if (manager instanceof SocketTrackingConnectionManager) { try { ((SocketTrackingConnectionManager) manager).close(); } catch (NullPointerException npe) { // ignore } catch (Exception ex) { // log - not much else to do log.warn("Exception closing underlying HTTP manager", ex); } } }
/** * Assume that the specified log is not set to Trace or Debug. * @param log the log to test * @throws AssumptionViolatedException if the assumption fails */ public static void notLogging(Log log) { assumeFalse(log.isTraceEnabled()); assumeFalse(log.isDebugEnabled()); }
/** * Use this to log a message with different levels of detail (or different * messages) at TRACE vs DEBUG log levels. Effectively, a substitute for: * <pre class="code"> * if (logger.isDebugEnabled()) { * String str = logger.isTraceEnabled() ? "..." : "..."; * if (logger.isTraceEnabled()) { * logger.trace(str); * } * else { * logger.debug(str); * } * } * </pre> * @param logger the logger to use to log the message * @param messageFactory function that accepts a boolean set to the value * of {@link Log#isTraceEnabled()} */ public static void traceDebug(Log logger, Function<Boolean, String> messageFactory) { if (logger.isDebugEnabled()) { String logMessage = messageFactory.apply(logger.isTraceEnabled()); if (logger.isTraceEnabled()) { logger.trace(logMessage); } else { logger.debug(logMessage); } } }
/** * Determine the exception handle method for the given exception. * @param exception the exception thrown * @return a handler for the given exception type, or {@code null} if none found */ @Nullable private Method getExceptionHandler(Throwable exception) { Class<?> exceptionClass = exception.getClass(); if (logger.isTraceEnabled()) { logger.trace("Trying to find handler for exception of type [" + exceptionClass.getName() + "]"); } Method handler = this.exceptionHandlerMap.get(exceptionClass); while (handler == null && exceptionClass != Throwable.class) { exceptionClass = exceptionClass.getSuperclass(); handler = this.exceptionHandlerMap.get(exceptionClass); } if (handler != null && logger.isTraceEnabled()) { logger.trace("Found handler for exception of type [" + exceptionClass.getName() + "]: " + handler); } return handler; }
protected void logTraceInformation(Resource bundle) { if (LOG.isTraceEnabled()) { if (bundle == null) { LOG.trace("Resolving bundle, bundle is null"); } else { LOG.trace("Resolving bundle, bundle is not null, bundle.exists() == " + bundle.exists() + " ,filename = " + bundle.getFilename()); try { LOG.trace("Resolving bundle - File Path" + bundle.getFile().getAbsolutePath()); } catch (IOException e) { LOG.error("IOException debugging bundle code", e); } } } }
/** * Detects handler methods at initialization. */ @Override public void afterPropertiesSet() { initHandlerMethods(); // Total includes detected mappings + explicit registrations via registerMapping.. int total = this.getHandlerMethods().size(); if ((logger.isTraceEnabled() && total == 0) || (logger.isDebugEnabled() && total > 0) ) { logger.debug(total + " mappings in " + formatMappingName()); } }
@Override protected int extractLink(int index, String content, SortedSet<ContentChunkInfo> linksToAdd) { if (content.substring(index, index + 4).equals("url(")) { // Ignore, UrlLinkParser will take care } else if (logger.isTraceEnabled()) { logger.trace("Unexpected syntax for @import link at index " + index); } return index; } }
@Override public int update(final PreparedStatementCreator psc, final KeyHolder generatedKeyHolder) throws DataAccessException { Assert.notNull(generatedKeyHolder, "KeyHolder must not be null"); logger.debug("Executing SQL update and returning generated keys"); return updateCount(execute(psc, ps -> { int rows = ps.executeUpdate(); List<Map<String, Object>> generatedKeys = generatedKeyHolder.getKeyList(); generatedKeys.clear(); ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<>(getColumnMapRowMapper(), 1); generatedKeys.addAll(result(rse.extractData(keys))); } finally { JdbcUtils.closeResultSet(keys); } } if (logger.isTraceEnabled()) { logger.trace("SQL update affected " + rows + " rows and returned " + generatedKeys.size() + " keys"); } return rows; })); }
/** * Initialize the MultipartResolver used by this class. * <p>If no bean is defined with the given name in the BeanFactory for this namespace, * no multipart handling is provided. */ private void initMultipartResolver(ApplicationContext context) { try { this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); if (logger.isTraceEnabled()) { logger.trace("Detected " + this.multipartResolver); } else if (logger.isDebugEnabled()) { logger.debug("Detected " + this.multipartResolver.getClass().getSimpleName()); } } catch (NoSuchBeanDefinitionException ex) { // Default is no multipart resolver. this.multipartResolver = null; if (logger.isTraceEnabled()) { logger.trace("No MultipartResolver '" + MULTIPART_RESOLVER_BEAN_NAME + "' declared"); } } }
@Override public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException { BeanDefinition bd = this.beanDefinitionMap.get(beanName); if (bd == null) { if (logger.isTraceEnabled()) { logger.trace("No bean named '" + beanName + "' found in " + this); } throw new NoSuchBeanDefinitionException(beanName); } return bd; }
if (wac == null) { String message = "Failed to find the root WebApplicationContext. Was ContextLoaderListener not used?"; logger.error(message); throw new IllegalStateException(message); if (wac.containsBean(beanName)) { T endpoint = wac.getBean(beanName, endpointClass); if (logger.isTraceEnabled()) { logger.trace("Using @ServerEndpoint singleton " + endpoint); if (ann != null && wac.containsBean(ann.value())) { T endpoint = wac.getBean(ann.value(), endpointClass); if (logger.isTraceEnabled()) { logger.trace("Using @ServerEndpoint singleton " + endpoint); if (logger.isTraceEnabled()) { logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass);
/** * Register all handlers found in the current ApplicationContext. * <p>The actual URL determination for a handler is up to the concrete * {@link #determineUrlsForHandler(String)} implementation. A bean for * which no such URLs could be determined is simply not considered a handler. * @throws org.springframework.beans.BeansException if the handler couldn't be registered * @see #determineUrlsForHandler(String) */ protected void detectHandlers() throws BeansException { ApplicationContext applicationContext = obtainApplicationContext(); String[] beanNames = (this.detectHandlersInAncestorContexts ? BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, Object.class) : applicationContext.getBeanNamesForType(Object.class)); // Take any bean name that we can determine URLs for. for (String beanName : beanNames) { String[] urls = determineUrlsForHandler(beanName); if (!ObjectUtils.isEmpty(urls)) { // URL paths found: Let's consider it a handler. registerHandler(urls, beanName); } } if ((logger.isDebugEnabled() && !getHandlerMap().isEmpty()) || logger.isTraceEnabled()) { logger.debug("Detected " + getHandlerMap().size() + " mappings in " + formatMappingName()); } }
private void scheduleConnectTimeoutTask(ConnectCallback connectHandler) { if (this.timeoutScheduler != null) { if (logger.isTraceEnabled()) { logger.trace("Scheduling connect to time out after " + this.timeoutValue + " ms."); } Date timeoutDate = new Date(System.currentTimeMillis() + this.timeoutValue); this.timeoutScheduler.schedule(connectHandler, timeoutDate); } else if (logger.isTraceEnabled()) { logger.trace("Connect timeout task not scheduled (no TaskScheduler configured)."); } }