Java Code Examples for org.apache.log4j.NDC#remove()
The following examples show how to use
org.apache.log4j.NDC#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log4JController.java From tutorials with MIT License | 6 votes |
@RequestMapping(value = "/ndc/log4j", method = RequestMethod.POST) public ResponseEntity<Investment> postPayment(@RequestBody Investment investment) { // Add transactionId and owner to NDC NDC.push("tx.id=" + investment.getTransactionId()); NDC.push("tx.owner=" + investment.getOwner()); try { log4jBusinessService.transfer(investment.getAmount()); } finally { // take out owner from the NDC stack NDC.pop(); // take out transactionId from the NDC stack NDC.pop(); NDC.remove(); } return new ResponseEntity<Investment>(investment, HttpStatus.OK); }
Example 2
Source File: Log4jNestedDiagnosticContextInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC after the request is processed. */ @Override public void afterCompletion(WebRequest request, Exception ex) throws Exception { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } }
Example 3
Source File: Log4jNestedDiagnosticContextInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC when the processing thread is * exited after the start of asynchronous request handling. */ @Override public void afterConcurrentHandlingStarted(WebRequest request) { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } }
Example 4
Source File: Log4jNestedDiagnosticContextFilter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC after the request is processed * and logs the after-request message through Log4J. */ @Override protected void afterRequest(HttpServletRequest request, String message) { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } if (log4jLogger.isDebugEnabled()) { log4jLogger.debug(message); } }
Example 5
Source File: Log4jNestedDiagnosticContextInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC after the request is processed. */ @Override public void afterCompletion(WebRequest request, Exception ex) throws Exception { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } }
Example 6
Source File: Log4jNestedDiagnosticContextInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC when the processing thread is * exited after the start of asynchronous request handling. */ @Override public void afterConcurrentHandlingStarted(WebRequest request) { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } }
Example 7
Source File: Log4jNestedDiagnosticContextFilter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Removes the log message from the Log4J NDC after the request is processed * and logs the after-request message through Log4J. */ @Override protected void afterRequest(HttpServletRequest request, String message) { NDC.pop(); if (NDC.getDepth() == 0) { NDC.remove(); } if (log4jLogger.isDebugEnabled()) { log4jLogger.debug(message); } }
Example 8
Source File: InitUsingDefaultConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) throws IOException { // Configure the LF5Appender using the DefaultLF5Configurator. This // will add the LF5Appender to the root of the Category tree. DefaultLF5Configurator.configure(); // Add an NDC to demonstrate how NDC information is output. NDC.push("#23856"); // Log some information. for (int i = 0; i < 10; i++) { logger.debug("Hello, my name is Homer Simpson."); logger.info("Mmmmmm .... Chocolate."); logger.warn("Mmm...forbidden donut."); } // Clean up NDC NDC.pop(); NDC.remove(); NDC.push("Another NDC"); // Log some information. logger.fatal("Hello, my name is Bart Simpson."); logger.error("Hi diddly ho good neighbour."); // Clean up NDC NDC.pop(); NDC.remove(); // Call methods on both classes. InitUsingDefaultConfigurator.foo(); InnerInitUsingDefaultConfigurator.foo(); logger.info("Exiting InitUsingDefaultConfigurator."); }
Example 9
Source File: InitUsingDefaultConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void foo() { logger.debug("Entered foo in InitUsingDefaultConfigurator class"); NDC.push("#123456"); logger.debug("Hello, my name is Marge Simpson."); logger.info("D'oh!! A deer! A female deer."); // Clean up NDC NDC.pop(); NDC.remove(); }
Example 10
Source File: Log4JContextClearingFilter.java From rice with Educational Community License v2.0 | 5 votes |
/** * Clear Log4J threadlocals */ protected static void clearLog4JThreadLocals() { NDC.remove(); MDC.clear(); ThreadLocal tl = getMDCThreadLocal(); if (tl != null) { tl.remove(); } }
Example 11
Source File: Log4JNDC.java From alfresco-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * Remove the diagnostic context for this thread. */ public void remove() { NDC.remove(); }
Example 12
Source File: NumberCruncherServer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public int[] factor(int number) throws RemoteException { // The client's host is an important source of information. try { NDC.push(getClientHost()); } catch(java.rmi.server.ServerNotActiveException e) { // we are being called from same VM NDC.push("localhost"); } // The information contained within the request is another source of // distinctive information. It might reveal the users name, date of request, // request ID etc. In servlet type environments, much information is // contained in cookies. NDC.push(String.valueOf(number)); logger.info("Beginning to factor."); if(number <= 0) { throw new IllegalArgumentException(number+" is not a positive integer."); } else if(number == 1) return new int[] {1}; Vector factors = new Vector(); int n = number; for(int i = 2; (i <= n) && (i*i <= number); i++) { // It is bad practice to place log requests within tight loops. // It is done here to show interleaved log output from // different requests. logger.debug("Trying to see if " + i + " is a factor."); if((n % i) == 0) { logger.info("Found factor "+i); factors.addElement(new Integer(i)); do { n /= i; } while((n % i) == 0); } // Placing artificial delays in tight-loops will also lead to sub-optimal // resuts. :-) delay(100); } if(n != 1) { logger.info("Found factor "+n); factors.addElement(new Integer(n)); } int len = factors.size(); int[] result = new int[len]; for(int i = 0; i < len; i++) { result[i] = ((Integer) factors.elementAt(i)).intValue(); } // Before leaving a thread we call NDC.remove. This deletes the reference // to the thread in the internal hash table. Version 0.8.5 introduces a // a lazy removal mechanism in case you forget to call remove when // exiting a thread. See the java documentation in NDC.remove for further // details. NDC.remove(); return result; }