當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。