本文整理匯總了Java中org.apache.log4j.NDC.pop方法的典型用法代碼示例。如果您正苦於以下問題:Java NDC.pop方法的具體用法?Java NDC.pop怎麽用?Java NDC.pop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.NDC
的用法示例。
在下文中一共展示了NDC.pop方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bubbleSort
import org.apache.log4j.NDC; //導入方法依賴的package包/類
void bubbleSort() {
LOG.info( "Entered the sort method.");
for(int i = intArray.length -1; i >= 0 ; i--) {
NDC.push("i=" + i);
OUTER.debug("in outer loop.");
for(int j = 0; j < i; j++) {
NDC.push("j=" + j);
// It is poor practice to ship code with log staments in tight loops.
// We do it anyway in this example.
INNER.debug( "in inner loop.");
if(intArray[j] > intArray[j+1])
swap(j, j+1);
NDC.pop();
}
NDC.pop();
}
}
示例2: test4
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* The pattern on the server side: %5p %x %X{key1}%X{key4} [%t] %c{1} - %m%n
* meaning that we are testing NDC, MDC and localization functionality across
* the wire.
*/
public void test4() throws Exception {
socketAppender = new SocketAppender("localhost", PORT);
socketAppender.setLocationInfo(true);
rootLogger.addAppender(socketAppender);
NDC.push("some");
common("T4", "key4", "MDC-TEST4");
NDC.pop();
delay(1);
//
// These tests check MDC operation which
// requires JDK 1.2 or later
if(!System.getProperty("java.version").startsWith("1.1.")) {
ControlFilter cf = new ControlFilter(new String[]{PAT4, EXCEPTION1,
EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP, FILTERED,
new Filter[] { cf, new LineNumberFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter() });
assertTrue(Compare.compare(FILTERED, "witness/socketServer.4"));
}
}
示例3: test8
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* The pattern on the server side: %5p %x %X{hostID}${key7} [%t] %c{1} - %m%n
*
* This test checks whether server side MDC works.
*/
public void test8() throws Exception {
socketAppender = new SocketAppender("localhost", PORT);
socketAppender.setLocationInfo(true);
rootLogger.addAppender(socketAppender);
NDC.push("some8");
common("T8", "key8", "MDC-TEST8");
NDC.pop();
delay(2);
//
// These tests check MDC operation which
// requires JDK 1.2 or later
if(!System.getProperty("java.version").startsWith("1.1.")) {
ControlFilter cf = new ControlFilter(new String[]{PAT8, EXCEPTION1,
EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP, FILTERED,
new Filter[] { cf, new LineNumberFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter() });
assertTrue(Compare.compare(FILTERED, "witness/socketServer.8"));
}
}
示例4: service
import org.apache.log4j.NDC; //導入方法依賴的package包/類
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
count_++;
String ndcName = getClass().getName();
ndcName = ndcName.substring(ndcName.lastIndexOf('.')+1);
NDC.push(ndcName);
NDC.push("call-" + count_);
logger_.info("begin onService");
try
{
onService(req, resp);
}
catch (Exception exc)
{
lastException = exc;
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
finally
{
logger_.info("end onService");
NDC.pop();
NDC.pop();
}
}
示例5: run
import org.apache.log4j.NDC; //導入方法依賴的package包/類
@Override
public void run() {
try {
final InetAddress remoteAddress = socket.getInetAddress();
NDC.push("DaemonWorker(" + socket.getRemoteSocketAddress() + ")");
try {
internalRun();
} finally {
NDC.pop();
}
} catch (RuntimeException e) {
if (e.getCause() instanceof SocketException) {
log.warn("worker exception", e);
} else if (e instanceof IllegalArgumentException) {
log.warn("worker exception", e);
} else {
log.error("worker exception", e);
}
throw e;
}
}
示例6: networkFault
import org.apache.log4j.NDC; //導入方法依賴的package包/類
@Override
public void networkFault(OneWireNetworkEvent e, String message) {
NDC.push("networkFault");
try {
// This is an event pertinent to everyone
consume(new DataSample<Double>(
System.currentTimeMillis(), type + getAddress(), type + getAddress(),
null, new OneWireIOException(message)));
} finally {
NDC.pop();
}
}
示例7: afterCompletion
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* 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();
}
}
示例8: afterConcurrentHandlingStarted
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* 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();
}
}
示例9: afterRequest
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* 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);
}
}
示例10: cleanDNC
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* Cleanes DNC context does pop and remove
*/
public static void cleanDNC() {
NDC.pop();
NDC.pop();
NDC.pop();
NDC.remove();
}
示例11: main
import org.apache.log4j.NDC; //導入方法依賴的package包/類
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.");
}
示例12: foo
import org.apache.log4j.NDC; //導入方法依賴的package包/類
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();
}
示例13: test5
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* The pattern on the server side: %5p %x %X{key1}%X{key5} [%t] %c{1} - %m%n
*
* The test case uses wraps an AsyncAppender around the
* SocketAppender. This tests was written specifically for bug
* report #9155.
* Prior to the bug fix the output on the server did not contain the
* MDC-TEST5 string because the MDC clone operation (in getMDCCopy
* method) operation is performed twice, once from the main thread
* which is correct, and a second time from the AsyncAppender's
* dispatch thread which is incrorrect.
*/
public void test5() throws Exception {
socketAppender = new SocketAppender("localhost", PORT);
socketAppender.setLocationInfo(true);
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setLocationInfo(true);
asyncAppender.addAppender(socketAppender);
rootLogger.addAppender(asyncAppender);
NDC.push("some5");
common("T5", "key5", "MDC-TEST5");
NDC.pop();
delay(2);
//
// These tests check MDC operation which
// requires JDK 1.2 or later
if(!System.getProperty("java.version").startsWith("1.1.")) {
ControlFilter cf = new ControlFilter(new String[]{PAT5, EXCEPTION1,
EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP, FILTERED,
new Filter[] { cf, new LineNumberFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter() });
assertTrue(Compare.compare(FILTERED, "witness/socketServer.5"));
}
}
示例14: test6
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* The pattern on the server side: %5p %x %X{hostID}${key6} [%t] %c{1} - %m%n
*
* This test checks whether client-side MDC overrides the server side.
* It uses an AsyncAppender encapsulating a SocketAppender
*/
public void test6() throws Exception {
socketAppender = new SocketAppender("localhost", PORT);
socketAppender.setLocationInfo(true);
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setLocationInfo(true);
asyncAppender.addAppender(socketAppender);
rootLogger.addAppender(asyncAppender);
NDC.push("some6");
MDC.put("hostID", "client-test6");
common("T6", "key6", "MDC-TEST6");
NDC.pop();
MDC.remove("hostID");
delay(2);
//
// These tests check MDC operation which
// requires JDK 1.2 or later
if(!System.getProperty("java.version").startsWith("1.1.")) {
ControlFilter cf = new ControlFilter(new String[]{PAT6, EXCEPTION1,
EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP, FILTERED,
new Filter[] { cf, new LineNumberFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter() });
assertTrue(Compare.compare(FILTERED, "witness/socketServer.6"));
}
}
示例15: test7
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* The pattern on the server side: %5p %x %X{hostID}${key7} [%t] %c{1} - %m%n
*
* This test checks whether client-side MDC overrides the server side.
*/
public void test7() throws Exception {
socketAppender = new SocketAppender("localhost", PORT);
socketAppender.setLocationInfo(true);
rootLogger.addAppender(socketAppender);
NDC.push("some7");
MDC.put("hostID", "client-test7");
common("T7", "key7", "MDC-TEST7");
NDC.pop();
MDC.remove("hostID");
delay(2);
//
// These tests check MDC operation which
// requires JDK 1.2 or later
if(!System.getProperty("java.version").startsWith("1.1.")) {
ControlFilter cf = new ControlFilter(new String[]{PAT7, EXCEPTION1,
EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP, FILTERED,
new Filter[] { cf, new LineNumberFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter() });
assertTrue(Compare.compare(FILTERED, "witness/socketServer.7"));
}
}