Details
-
New Feature
-
Resolution: Unresolved
-
Major
-
None
-
0.9.15
-
None
-
None
Description
The discussion about NDC vs. MDC has been done going for quite a while. I don't think MDC is a suitable replacement for NDC, except insofar as NDC can be implemented using MDC.
Enclosed is the NDC implementation we're started using at Electric Cloud. Please feel free to adapt/modify/enhance it as you see fit. We place this code in the public domain in case others find it useful.
Attachment to come as well.
// NDC.java –
//
// NDC.java is part of the ElectricCommander server.
//
// Copyright (c) 2005-2009 Electric Cloud, Inc.
// All rights reserved.
//
package com.electriccloud.log;
import java.util.Deque;
import java.util.LinkedList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.slf4j.MDC;
/**
- Utility object that implements NDC using MDC.
*/
@SuppressWarnings( {"UtilityClass", "StringContatenationInLoop"})
public class NDC
{
//~ Static fields/initializers ---------------------------------------------
private static final ThreadLocal<Deque<String>> s_stack =
new ThreadLocal<Deque<String>>() {
@Override @SuppressWarnings(
)
protected Deque<String> initialValue()
};
//~ Constructors -----------------------------------------------------------
private NDC()
{
}
//~ Methods ----------------------------------------------------------------
public static void pop()
{
Deque<String> stack = s_stack.get();
// Pop the stack if isn't already empty
if (!stack.isEmpty())
// Put the previous value in the MDC (null if the stack is now empty)
MDC.put("NDC", stack.peek());
}
@SuppressWarnings(
{"HardCodedStringLiteral"})
public static void push(@NonNls @NotNull String format, Object... args)
}