本文整理汇总了Java中org.apache.logging.log4j.ThreadContext类的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext类的具体用法?Java ThreadContext怎么用?Java ThreadContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadContext类属于org.apache.logging.log4j包,在下文中一共展示了ThreadContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: complete
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void complete(final Channel channel, final O ioTask) {
ThreadContext.put(KEY_CLASS_NAME, CLS_NAME);
ThreadContext.put(KEY_TEST_STEP_ID, stepId);
try {
ioTask.finishResponse();
} catch(final IllegalStateException e) {
LogUtil.exception(Level.DEBUG, e, "{}: invalid I/O task state", ioTask.toString());
}
if(channel != null) {
connPool.release(channel);
}
ioTaskCompleted(ioTask);
}
示例2: invoke
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void invoke(Event event)
{
if (GETCONTEXT)
ThreadContext.put("mod", owner == null ? "" : owner.getName());
if (handler != null)
{
if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
{
if (filter == null || filter == ((IGenericEvent)event).getGenericType())
{
handler.invoke(event);
}
}
}
if (GETCONTEXT)
ThreadContext.remove("mod");
}
示例3: LoggingApp
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
public LoggingApp(final String member) {
ThreadContext.clear();
RequestContext.setSessionId("session1234");
RequestContext.setIpAddress("127.0.0.1");
RequestContext.setClientId("02121");
RequestContext.setProductName("IB");
RequestContext.setProductVersion("4.18.1");
RequestContext.setLocale("en_US");
RequestContext.setRegion("prod");
if (events == null) {
events = MockEventsSupplier.getAllEvents(member);
}
}
示例4: resolve
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
ThreadContext.ContextStack contextStack = logEvent.getContextStack();
if (contextStack.getDepth() == 0) {
return null;
}
Pattern itemPattern = context.getNdcPattern();
ArrayNode contextStackNode = context.getObjectMapper().createArrayNode();
for (String contextStackItem : contextStack.asList()) {
boolean matches = itemPattern == null || itemPattern.matcher(contextStackItem).matches();
if (matches) {
contextStackNode.add(contextStackItem);
}
}
return contextStackNode;
}
示例5: invoke
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void invoke(Event event)
{
if (owner != null && GETCONTEXT)
{
ThreadContext.put("mod", owner.getName());
}
else if (GETCONTEXT)
{
ThreadContext.put("mod", "");
}
if (handler != null)
{
if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
{
handler.invoke(event);
}
}
if (GETCONTEXT)
ThreadContext.remove("mod");
}
示例6: sessionEvent
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void sessionEvent(MCRSessionEvent event) {
switch (event.getType()) {
case activated:
ThreadContext.put("ipAddress", event.getSession().getCurrentIP());
ThreadContext.put("loginId", event.getSession().getUserInformation().getUserID());
ThreadContext.put("mcrSession", event.getSession().getID());
ThreadContext.put("language", event.getSession().getCurrentLanguage());
break;
case passivated:
ThreadContext.clearMap();
break;
default:
break;
}
}
示例7: doFilter
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
String id = UUID.randomUUID().toString();
ThreadContext.put("id", id);
try {
HttpServletResponse resp = (HttpServletResponse) response;
resp.setHeader("Log-ID", id);
chain.doFilter(request, response);
} catch (Throwable e) {
logger.error("error", e);
} finally {
ThreadContext.remove("id");
ThreadContext.remove("username");
}
}
示例8: clear
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static void clear() {
// CB ThreadLocals
MethodInterceptorContext.cleanupThread();
AppRegistry.cleanupThread();
MessageBus.cleanupThread();
GeemoduleRegistry.cleanupThread();
// Clear Log4j which is causing memory leaks
ThreadContext.clearAll();
// Also clear this one to be on the safe side
MDC.clear();
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
for (Thread t : threadArray) {
if (t.getName().contains("Abandoned connection cleanup thread")
|| t.getName().matches("com\\.google.*Finalizer")) {
synchronized (t) {
t.stop();
}
}
}
}
示例9: initMerchantLogger
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
protected void initMerchantLogger() {
ApplicationContext appCtx = App.get().context();
Merchant merchant = appCtx.getMerchant();
Store store = appCtx.getStore();
String logPath = merchant.getLogPath();
// Log4j does not like backslashes in directory path.
logPath = logPath.replace(Char.BACKSLASH, Char.SLASH);
ThreadContext.put("log.route.name", "CB-App-Rolling-Log");
ThreadContext.put("log.path", logPath);
ThreadContext.put("appctx.merchant", merchant.getCompanyName());
ThreadContext.put("appctx.store", store.getName());
log = LogManager.getLogger(getClass());
}
示例10: doFilterInternal
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void doFilterInternal(final HttpServletRequest request,
final HttpServletResponse response, final FilterChain fc)
throws IOException, ServletException {
String allowedMtds = (RequestMethod.GET.name() + "," +
RequestMethod.POST.name() + "," + RequestMethod.PATCH.name());
response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
HttpHeaders.CONTENT_TYPE);
response.setHeader(HttpHeaders.ALLOW, allowedMtds);
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
(HttpHeaders.ACCEPT));
ThreadContext.put("ipAddress", request.getRemoteAddr());
ThreadContext.put("responseStatus", String.valueOf(
response.getStatus()));
fc.doFilter(request, response);
ThreadContext.clearAll();
}
示例11: testName
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Test
public void testName() throws Exception {
// Log in Main Thread
logger.info("Log in main!");
final ExecutorService executorService = Executors.newFixedThreadPool(2);
// Run task in thread pool
executorService.submit(createTask()).get();
// Init Log Context, set TTL
// More KV if needed
final String TRACE_ID = "trace-id";
final String TRACE_ID_VALUE = "XXX-YYY-ZZZ";
ThreadContext.put(TRACE_ID, TRACE_ID_VALUE);
// Log in Main Thread
logger.info("Log in main!");
executorService.submit(createTask()).get();
logger.info("Exit main");
executorService.shutdown();
}
示例12: invoke
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void invoke(Event event)
{
if (owner != null)
{
ThreadContext.put("mod", owner.getName());
}
else
{
ThreadContext.put("mod", "");
}
if (handler != null)
{
if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
{
handler.invoke(event);
}
}
ThreadContext.remove("mod");
}
示例13: setThreadLoggingContext
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
private void setThreadLoggingContext(Message msg) {
ThreadContext.clearAll();
if (msg instanceof APIMessage) {
ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
} else {
Map<String, String> ctx = msg.getHeaderEntry(TASK_CONTEXT);
if (ctx != null) {
ThreadContext.putAll(ctx);
}
}
if (msg.getHeaders().containsKey(TASK_STACK)) {
List<String> taskStack = msg.getHeaderEntry(TASK_STACK);
ThreadContext.setStack(taskStack);
}
}
示例14: beforeExecute
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
protected void beforeExecute(Thread t, Runnable r) {
ThreadContext.clearMap();
ThreadContext.clearStack();
ThreadAroundHook debugHook = null;
List<ThreadAroundHook> tmpHooks;
synchronized (_hooks) {
tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
}
for (ThreadAroundHook hook : tmpHooks) {
debugHook = hook;
try {
hook.beforeExecute(t, r);
} catch (Exception e) {
_logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
}
}
}
示例15: afterExecute
import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
protected void afterExecute(Runnable r, Throwable t) {
ThreadContext.clearMap();
ThreadContext.clearStack();
ThreadAroundHook debugHook = null;
List<ThreadAroundHook> tmpHooks;
synchronized (_hooks) {
tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
}
for (ThreadAroundHook hook : tmpHooks) {
debugHook = hook;
try {
hook.afterExecute(r, t);
} catch (Exception e) {
_logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
}
}
}