本文整理匯總了Java中org.apache.log4j.NDC.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java NDC.clear方法的具體用法?Java NDC.clear怎麽用?Java NDC.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.NDC
的用法示例。
在下文中一共展示了NDC.clear方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNDC
import org.apache.log4j.NDC; //導入方法依賴的package包/類
@Test
public void testNDC() throws Exception
{
initialize("TestJsonLayout/default.properties");
NDC.push("frist"); // misspelling intentional
NDC.push("second");
logger.debug(TEST_MESSAGE);
NDC.clear();
captureLoggingOutput();
assertCommonElements(TEST_MESSAGE);
DomAsserts.assertEquals("ndc", "frist second", dom, "/data/ndc");
}
示例2: testNDCWithCDATA
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* Tests CDATA element within NDC content. See bug 37560.
*/
public void testNDCWithCDATA() throws Exception {
Logger logger = Logger.getLogger("com.example.bar");
Level level = Level.INFO;
String ndcMessage ="<envelope><faultstring><![CDATA[The EffectiveDate]]></faultstring><envelope>";
NDC.push(ndcMessage);
LoggingEvent event =
new LoggingEvent(
"com.example.bar", logger, level, "Hello, World", null);
Layout layout = createLayout();
String result = layout.format(event);
NDC.clear();
Element parsedResult = parse(result);
NodeList ndcs = parsedResult.getElementsByTagName("log4j:NDC");
assertEquals(1, ndcs.getLength());
StringBuffer buf = new StringBuffer();
for(Node child = ndcs.item(0).getFirstChild();
child != null;
child = child.getNextSibling()) {
buf.append(child.getNodeValue());
}
assertEquals(ndcMessage, buf.toString());
}
示例3: shutdown
import org.apache.log4j.NDC; //導入方法依賴的package包/類
@Override
protected void shutdown() throws Throwable {
NDC.push("shutdown");
try {
logger.info("Stopping monitor...");
monitor.stop().waitFor();
logger.info("Stopped");
} finally {
NDC.pop();
NDC.clear();
}
}
示例4: setUp
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* Clear MDC and NDC before test.
*/
public void setUp() {
NDC.clear();
if (MDC.getContext() != null) {
MDC.getContext().clear();
}
}
示例5: clear
import org.apache.log4j.NDC; //導入方法依賴的package包/類
public static void clear() {
if (NDCEnabled) {
NDC.clear();
}
}
示例6: execute
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void execute() throws Throwable {
NDC.push("execute");
try {
while (isEnabled()) {
try {
browse();
// Currently, browse() takes 10+ seconds. Let's give them a
// break
try {
rescanNow.waitFor(timeout);
logger.debug("Rescan requested");
forcedRescan = true;
} catch (SemaphoreTimeoutException ignored) {
// Don't do anything, this is a normal outcome when the
// semaphore times out, which happens every time the
// rescan() wasn't called.
forcedRescan = false;
}
} catch (Throwable t) {
String message = t.getMessage();
if (message != null && message.startsWith("Error short")) {
logger.fatal("1-Wire Network shorted out!!!", t);
// VT: FIXME: This is a critical failure. All the
// listeners must be notified immediately - this most
// probably means loss of all sensors, and what's worse,
// this means loss of control over HVAC actuator
// devices, though the devices themselves have to be
// powered and therefore keep their state - in other
// words, if the HVAC is on, it will stay on. Very Bad
// Thing (TM).
// Well, and of course, it *has* to be this inconvenient
// - the only place where a network short can be
// detected is where you actually *write* something to
// it. Both places are outside of normal control flow,
// and they're asynchronous.
handleShortCircuit();
// Now, the short circuit is a condition that is
// detected at the very beginning of browse(), very
// fast. Let to its own devices, this will cycle
// indefinitely, so it would be a good idea to restrict
// the cycle rate.
Thread.sleep(1000);
} else {
logger.warn("Browse failure:", t);
}
}
}
} finally {
NDC.pop();
NDC.clear();
}
}
示例7: execute
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* Keep polling the device state until stopped.
*
* @exception Throwable if anything goes wrong.
*/
@Override
protected final void execute() throws Throwable {
NDC.push("execute");
try {
while (isEnabled()) {
try {
poll();
} catch (ConcurrentModificationException ex) {
// No big deal
logger.debug("Arrival/departure during poll, ignored", ex);
} catch (Throwable t) {
logger.error("Poll broken:", t);
// dumpMap(path2device, "path2device");
// Possibly, the cause of this was a network departure.
// Let's refresh the device map
monitor.rescan().waitFor();
}
}
} finally {
NDC.pop();
NDC.clear();
}
}
示例8: browse
import org.apache.log4j.NDC; //導入方法依賴的package包/類
/**
* Find all devices on 1-Wire® network.
* <p>
* This is an intrusive search that is going to shuffle all the MicroLAN
* couplers on the network.
*
* @throws Throwable if anything goes wrong.
*/
private void browse() throws Throwable {
NDC.push("browse");
Marker m = new Marker("browse");
lock.writeLock().lock();
m.checkpoint("got lock");
try {
if (forcedRescan) {
logger.info("Forced rescan");
}
Map<String, OneWireContainer> address2deviceLocal = new TreeMap<String, OneWireContainer>();
Map<String, OWPath> address2pathLocal = new TreeMap<String, OWPath>();
NDC.push("browseProper");
Marker m2 = new Marker("browseProper");
try {
adapter.setSearchAllDevices();
adapter.targetAllFamilies();
OWPath rootPath = new OWPath(adapter);
browse(rootPath, address2deviceLocal, address2pathLocal);
} finally {
m2.close();
NDC.pop();
}
NDC.push("handleChanges");
Marker m3 = new Marker("handleChanges");
try {
handleDepartures(address2deviceLocal, address2pathLocal);
handleArrivals(address2deviceLocal, address2pathLocal);
address2device = address2deviceLocal;
address2path = address2pathLocal;
} finally {
m3.close();
NDC.pop();
}
logger.debug("Rescan complete");
rescanComplete.post();
if (address2deviceLocal.isEmpty()) {
logger.warn("No devices found, waiting 10 seconds to avoid runaway looping");
Thread.sleep(10000);
}
} finally {
forcedRescan = false;
lock.writeLock().unlock();
m.close();
NDC.pop();
NDC.clear();
}
}
示例9: startup
import org.apache.log4j.NDC; //導入方法依賴的package包/類
@Override
protected void startup() throws Throwable {
NDC.push("startup");
try {
Set<String> portsAvailable = getPortsAvailable();
if (adapter == null) {
throw new IllegalArgumentException("Port '" + adapterPort + "' unavailable, valid values: "
+ portsAvailable + "\n"
+ "Things to check:\n"
+ " http://stackoverflow.com/questions/9628988/ubuntu-rxtx-does-not-recognize-usb-serial-device yet?");
}
if (!adapter.selectPort(adapterPort)) {
// VT: NOTE: Having succeeded at selecting the port doesn't
// necessarily mean that we'll be fine. Serial based adapters
// don't seem to be accessed during selectPort(), and it's quite
// possible to successfully select a non-existing port.
// Additional test is required to make sure we're OK.
throw new IllegalArgumentException("Unable to select port '" + adapterPort
+ "', make sure it's the right one (available: " + portsAvailable + ")");
}
try {
// Now, *this* should take care of it...
adapter.reset();
} catch (OneWireIOException ex) {
if ("Error communicating with adapter".equals(ex.getMessage())) {
throw new IOException("Port '" + adapterPort
+ "' doesn't seem to have adapter connected, check others: " + portsAvailable, ex);
}
}
logger.info("Adapter class: " + adapter.getClass().getName());
logger.info("Adapter port: " + adapterPort);
// VT: NOTE: It is not necessary to use the lock at this point
// because the service is not yet started
try {
logger.info("Setting adapter speed to " + speedInt2speedName.get(adapterSpeed));
adapter.setSpeed(adapterSpeed);
} catch (Throwable t) {
logger.error("Failed to set adapter speed, cause:", t);
}
monitor = new OneWireNetworkMonitor(adapter, lock);
synchronized (this) {
// This is necessary to release getMonitor()
notifyAll();
}
monitor.start();
monitor.addListener(this);
monitor.getSemUp().waitFor();
logger.info("started");
} finally {
NDC.pop();
NDC.clear();
}
}