当前位置: 首页>>代码示例>>Java>>正文


Java MDC.clear方法代码示例

本文整理汇总了Java中org.slf4j.MDC.clear方法的典型用法代码示例。如果您正苦于以下问题:Java MDC.clear方法的具体用法?Java MDC.clear怎么用?Java MDC.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.slf4j.MDC的用法示例。


在下文中一共展示了MDC.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilter

import org.slf4j.MDC; //导入方法依赖的package包/类
/**
 * Sets the slf4j <code>MDC</code> and delegates the request to the chain.
 *
 * @param request servlet request.
 * @param response servlet response.
 * @param chain filter chain.
 *
 * @throws IOException thrown if an IO error occurrs.
 * @throws ServletException thrown if a servet error occurrs.
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  throws IOException, ServletException {
  try {
    MDC.clear();
    String hostname = HostnameFilter.get();
    if (hostname != null) {
      MDC.put("hostname", HostnameFilter.get());
    }
    Principal principal = ((HttpServletRequest) request).getUserPrincipal();
    String user = (principal != null) ? principal.getName() : null;
    if (user != null) {
      MDC.put("user", user);
    }
    MDC.put("method", ((HttpServletRequest) request).getMethod());
    MDC.put("path", ((HttpServletRequest) request).getPathInfo());
    chain.doFilter(request, response);
  } finally {
    MDC.clear();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:MDCFilter.java

示例2: initialize

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public final void initialize(Bootstrap<SamlEngineConfiguration> bootstrap) {
    // Enable variable substitution with environment variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    MDC.clear();
    bootstrap.addBundle(new ServiceStatusBundle());
    bootstrap.addBundle(new MonitoringBundle());
    bootstrap.addBundle(new LoggingBundle());
    bootstrap.addBundle(new IdaJsonProcessingExceptionMapperBundle());
    final InfinispanBundle infinispanBundle = new InfinispanBundle();
    bootstrap.addBundle(infinispanBundle);
    guiceBundle = defaultBuilder(SamlEngineConfiguration.class)
            .modules(new SamlEngineModule(), new CryptoModule(), bindInfinispan(infinispanBundle.getInfinispanCacheManagerProvider()))
            .build();
    bootstrap.addBundle(guiceBundle);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:22,代码来源:SamlEngineApplication.java

示例3: call

import org.slf4j.MDC; //导入方法依赖的package包/类
public T call() throws Exception {
  MDC.setContextMap(contextMap);
  try {
    return target.call();
  }
  finally {
    MDC.clear();
  }
}
 
开发者ID:zacharee,项目名称:RCTDRemoverforLG,代码行数:10,代码来源:MDCCallableAdapter.java

示例4: doFilter

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    try {
        HttpServletRequest req = (HttpServletRequest) request;
        String requestId = req.getHeader(REQUEST_ID_HEADER);
        requestId = (StringUtils.isBlank(requestId)) ? generateRequestId() : requestId;

        String keycloakToken = req.getHeader(AUTHORIZATION_HEADER);
        String identityId = getIdentityId(keycloakToken);

        MDC.put(REQUEST_ID_MDC_KEY, requestId);
        MDC.put(IDENTITY_ID_MDC_KEY, identityId);
        chain.doFilter(request, response);
    } finally {
        MDC.clear();
    }
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:19,代码来源:RequestFilter.java

示例5: process

import org.slf4j.MDC; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
    String key = (String)exchange.getIn().getHeader(WebsocketConstants.CONNECTION_KEY);

    MDC.clear();
    MDC.put("WebsocketConstants.CONNECTION_KEY",key);

    logger.info("Headers: {}",exchange.getIn().getHeaders());
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:9,代码来源:SimpleSignalingExample.java

示例6: doFilter

import org.slf4j.MDC; //导入方法依赖的package包/类
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    // 目前只生成线程编号.
    Trace trace = new Trace();
    SystemContext.setTrace(trace.getThreadTrace());
    MDC.put("Trace", SystemContext.getTrace());
    System.out.println("  filer is running  ");
    filterChain.doFilter(request, response);
    MDC.clear();
    SystemContext.clean();
}
 
开发者ID:easymall,项目名称:easymall,代码行数:13,代码来源:SystemFilter.java

示例7: doFilter

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    try {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            Object principal = authentication.getPrincipal();
            if(principal instanceof User) { // ugly
                User user = (User) principal;
                MDC.put("userId", user.getId().toString());
            }
        }
        chain.doFilter(request, response);
    } finally {
        MDC.clear();
    }
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:17,代码来源:TulevaRollbarFilter.java

示例8: wrap

import org.slf4j.MDC; //导入方法依赖的package包/类
/**
 * Simple wrapper which copies over the context (MDC and correlation) to the executing thread and
 * logs uncaught exceptions
 */
public static Runnable wrap(Runnable in, Supplier<String> correlationIdProvider, Consumer<String> correlationIdSetter) {
    final Optional<Map<String, String>> context = Optional.ofNullable(MDC.getCopyOfContextMap());
    final Optional<String> korrelasjonsId = Optional.ofNullable(correlationIdProvider.get());
    return () -> {
        Optional<Map<String, String>> contextBackup = Optional.ofNullable(MDC.getCopyOfContextMap());
        final Optional<String> backupKorrelasjonsId = Optional.ofNullable(correlationIdProvider.get());
        context.ifPresent(MDC::setContextMap);
        korrelasjonsId.ifPresent(correlationIdSetter);
        try {
            in.run();
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw e;
        } finally {
            MDC.clear();
            contextBackup.ifPresent(MDC::setContextMap);
            backupKorrelasjonsId.ifPresent(correlationIdSetter);
        }
    };
}
 
开发者ID:systek,项目名称:dataflow,代码行数:25,代码来源:ContextSwitcher.java

示例9: afterTestMethod

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void afterTestMethod(TestContext testContext) {
    Method method = testContext.getTestMethod();
    if (DataSetAnnotationUtils.isRun(method)) {
        try {
            DataProcessor dataProcessor = testContext.
                    getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
            boolean success = dataProcessor.compareResult(method);
            if (!success) {
                logger.info("Data test result : failure");
                Assert.fail();
            }
        } catch (EasyTestException e) {
            logger.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
    logger.info("Data test result : success");
    MDC.clear();
}
 
开发者ID:easymall,项目名称:easy-test,代码行数:21,代码来源:JunitCaseListener.java

示例10: run

import org.slf4j.MDC; //导入方法依赖的package包/类
public void run() {
  MDC.setContextMap(contextMap);
  try {
    target.run();
  }
  finally {
    MDC.clear();
  }
}
 
开发者ID:zacharee,项目名称:RCTDRemoverforLG,代码行数:10,代码来源:MDCRunnableAdapter.java

示例11: decorate

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public Runnable decorate(Runnable runnable) {
    Map<String, String> contextMap = MDC.getCopyOfContextMap();
    return () -> {
        try {
            MDC.setContextMap(contextMap);
            runnable.run();
        } finally {
            MDC.clear();
        }
    };
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:13,代码来源:MdcTaskDecorator.java

示例12: not_match_when_a_mdc_keys_is_different

import org.slf4j.MDC; //导入方法依赖的package包/类
@Test
public void not_match_when_a_mdc_keys_is_different() {
  MDC.put("aKey", "differentValue");
  MDC.put("anotherKey", "anotherValue");
  LoggingEvent logEvent = aLoggingEventWith(INFO, "message");
  ExpectedLoggingMessage expectedLoggingMessage = aLog()
    .withMdc("aKey", equalTo("unmatchedValue"))
    .withMdc("anotherKey", equalTo("anotherValue"));

  boolean matches = expectedLoggingMessage.matches(logEvent);

  MDC.clear();
  assertThat(matches).isFalse();
}
 
开发者ID:mustaine,项目名称:logcapture,代码行数:15,代码来源:ExpectedLoggingMessageShould.java

示例13: run

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void run() {
    RequestContextAccessor.set(requestContext);

    if (mdcContents != null) {
        MDC.setContextMap(mdcContents);
    }

    runnable.run();

    MDC.clear();
    RequestContextAccessor.remove();
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:14,代码来源:WayfRunnable.java

示例14: execute

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    MDC.put("trigger", context.getTrigger().getKey().toString());

    job.execute(context);

    MDC.clear();
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:9,代码来源:TriggerAwareLoggingJob.java

示例15: doFilter

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
                     final FilterChain filterChain) throws IOException, ServletException {
    try {
        final HttpServletRequest request = (HttpServletRequest) servletRequest;

        addContextAttribute("remoteAddress", request.getRemoteAddr());
        addContextAttribute("remoteUser", request.getRemoteUser());
        addContextAttribute("serverName", request.getServerName());
        addContextAttribute("serverPort", String.valueOf(request.getServerPort()));
        addContextAttribute("locale", request.getLocale().getDisplayName());
        addContextAttribute("contentType", request.getContentType());
        addContextAttribute("contextPath", request.getContextPath());
        addContextAttribute("localAddress", request.getLocalAddr());
        addContextAttribute("localPort", String.valueOf(request.getLocalPort()));
        addContextAttribute("remotePort", String.valueOf(request.getRemotePort()));
        addContextAttribute("pathInfo", request.getPathInfo());
        addContextAttribute("protocol", request.getProtocol());
        addContextAttribute("authType", request.getAuthType());
        addContextAttribute("method", request.getMethod());
        addContextAttribute("queryString", request.getQueryString());
        addContextAttribute("requestUri", request.getRequestURI());
        addContextAttribute("scheme", request.getScheme());
        addContextAttribute("timezone", TimeZone.getDefault().getDisplayName());

        final Map<String, String[]> params = request.getParameterMap();
        params.keySet().forEach(k -> {
            final String[] values = params.get(k);
            addContextAttribute(k, Arrays.toString(values));
        });

        Collections.list(request.getAttributeNames())
                .forEach(a -> addContextAttribute(a, request.getAttribute(a)));

        final String cookieValue = this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
        if (StringUtils.isNotBlank(cookieValue)) {
            final Principal p = this.ticketRegistrySupport.getAuthenticatedPrincipalFrom(cookieValue);
            if (p != null) {
                addContextAttribute("principal", p.getId());
            }
        }
        filterChain.doFilter(servletRequest, servletResponse);
    } finally {
        MDC.clear();
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:47,代码来源:ThreadContextMDCServletFilter.java


注:本文中的org.slf4j.MDC.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。