List of usage examples for org.apache.commons.logging Log debug
void debug(Object message);
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 ww . j av 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.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 w w w .ja va 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.core.log.LogFormatUtils.java
/** * 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">//w w w.jav a 2 s . c om * 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()) { boolean traceEnabled = logger.isTraceEnabled(); String logMessage = messageFactory.apply(traceEnabled); if (traceEnabled) { logger.trace(logMessage); } else { logger.debug(logMessage); } } }
From source file:org.springframework.extensions.surf.core.scripts.ScriptResourceHelper.java
/** * Recursively resolve imports in the specified scripts, adding the imports to the * specific list of scriplets to combine later. * //from w ww. j ava 2 s. c o m * @param location Script location - used to ensure duplicates are not added * @param script The script to recursively resolve imports for * @param scripts The collection of scriplets to execute with imports resolved and removed */ private static void recurseScriptImports(String location, String script, ScriptResourceLoader loader, Map<String, String> scripts, Log logger) { int index = 0; // skip any initial whitespace for (; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } // Allow a comment marker to immediately precede the IMPORT_PREFIX to assist JS validation. if (script.startsWith(IMPORT_COMMENT_MARKER, index)) { index += IMPORT_COMMENT_MARKER.length(); } // look for the "<import" directive marker if (script.startsWith(IMPORT_PREFIX, index)) { // skip whitespace between "<import" and "resource" boolean afterWhitespace = false; index += IMPORT_PREFIX.length() + 1; for (; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { afterWhitespace = true; break; } } if (afterWhitespace == true && script.startsWith(IMPORT_RESOURCE, index)) { // found an import line! index += IMPORT_RESOURCE.length(); int resourceStart = index; for (; index < script.length(); index++) { if (script.charAt(index) == '"' && script.charAt(index + 1) == '>') { // found end of import line - so we have a resource path String resource = script.substring(resourceStart, index); if (logger.isDebugEnabled()) logger.debug("Found script resource import: " + resource); if (scripts.containsKey(resource) == false) { // load the script resource (and parse any recursive includes...) String includedScript = loader.loadScriptResource(resource); if (includedScript != null) { if (logger.isDebugEnabled()) logger.debug("Succesfully located script '" + resource + "'"); recurseScriptImports(resource, includedScript, loader, scripts, logger); } } else { if (logger.isDebugEnabled()) logger.debug("Note: already imported resource: " + resource); } // continue scanning this script for additional includes // skip the last two characters of the import directive for (index += 2; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } recurseScriptImports(location, script.substring(index), loader, scripts, logger); return; } } // if we get here, we failed to find the end of an import line throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } else { throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } } else { // no (further) includes found - include the original script content if (logger.isDebugEnabled()) logger.debug("Imports resolved, adding resource '" + location); if (logger.isTraceEnabled()) logger.trace(script); scripts.put(location, script); } }
From source file:org.springframework.integration.file.remote.RemoteFileUtils.java
/** * Recursively create remote directories. * @param <F> The session type./*from ww w . ja va 2 s. c om*/ * @param path The directory path. * @param session The session. * @throws IOException */ public static <F> void makeDirectories(String path, Session<F> session, String remoteFileSeparator, Log logger) throws IOException { if (!session.exists(path)) { int nextSeparatorIndex = path.lastIndexOf(remoteFileSeparator); if (nextSeparatorIndex > -1) { List<String> pathsToCreate = new LinkedList<String>(); while (nextSeparatorIndex > -1) { String pathSegment = path.substring(0, nextSeparatorIndex); if (pathSegment.length() == 0 || session.exists(pathSegment)) { // no more paths to create break; } else { pathsToCreate.add(0, pathSegment); nextSeparatorIndex = pathSegment.lastIndexOf(remoteFileSeparator); } } for (String pathToCreate : pathsToCreate) { if (logger.isDebugEnabled()) { logger.debug("Creating '" + pathToCreate + "'"); } session.mkdir(pathToCreate); } } else { session.mkdir(path); } } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
private void onMessageSync(javax.jms.Message message, String correlationId) { try {//from w w w .jav a2 s. c om LinkedBlockingQueue<javax.jms.Message> queue = this.replies.get(correlationId); if (queue == null) { if (this.correlationKey != null) { Log debugLogger = LogFactory.getLog("si.jmsgateway.debug"); if (debugLogger.isDebugEnabled()) { Object siMessage = this.messageConverter.fromMessage(message); debugLogger.debug("No pending reply for " + siMessage + " with correlationId: " + correlationId + " pending replies: " + this.replies.keySet()); } throw new RuntimeException("No sender waiting for reply"); } synchronized (this.earlyOrLateReplies) { queue = this.replies.get(correlationId); if (queue == null) { if (logger.isDebugEnabled()) { logger.debug("Reply for correlationId " + correlationId + " received early or late"); } this.earlyOrLateReplies.put(correlationId, new TimedReply(message)); } } } if (queue != null) { if (logger.isDebugEnabled()) { logger.debug("Received reply with correlationId " + correlationId); } queue.add(message); } } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Failed to consume reply with correlationId " + correlationId, e); } } }
From source file:org.springframework.kafka.support.SeekUtils.java
/** * Seek records to earliest position, optionally skipping the first. * @param records the records.// ww w. jav a 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.security.web.session.HttpSessionEventPublisher.java
/** * Handles the HttpSessionEvent by publishing a {@link HttpSessionCreatedEvent} to the * application appContext./*from w ww.ja v a 2s . c om*/ * * @param event HttpSessionEvent passed in by the container */ public void sessionCreated(HttpSessionEvent event) { HttpSessionCreatedEvent e = new HttpSessionCreatedEvent(event.getSession()); Log log = LogFactory.getLog(LOGGER_NAME); if (log.isDebugEnabled()) { log.debug("Publishing event: " + e); } getContext(event.getSession().getServletContext()).publishEvent(e); }
From source file:org.springframework.security.web.session.HttpSessionEventPublisher.java
/** * Handles the HttpSessionEvent by publishing a {@link HttpSessionDestroyedEvent} to * the application appContext.//from w w w . j a v a2 s .c o m * * @param event The HttpSessionEvent pass in by the container */ public void sessionDestroyed(HttpSessionEvent event) { HttpSessionDestroyedEvent e = new HttpSessionDestroyedEvent(event.getSession()); Log log = LogFactory.getLog(LOGGER_NAME); if (log.isDebugEnabled()) { log.debug("Publishing event: " + e); } getContext(event.getSession().getServletContext()).publishEvent(e); }
From source file:org.springframework.util.Log4jConfigurerTests.java
private void doTestInitLogging(String location, boolean refreshInterval) throws FileNotFoundException { if (refreshInterval) { Log4jConfigurer.initLogging(location, 10); } else {//w w w . j a va2s .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); }