本文整理匯總了Java中org.slf4j.MDC.get方法的典型用法代碼示例。如果您正苦於以下問題:Java MDC.get方法的具體用法?Java MDC.get怎麽用?Java MDC.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.slf4j.MDC
的用法示例。
在下文中一共展示了MDC.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCorrelationId
import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public String getCorrelationId() {
HttpHeaders headers = ResteasyProviderFactory.getContextData(HttpHeaders.class);
String correlationId;
if (headers != null) {
correlationId = headers.getHeaderString(headerName);
if (correlationId != null) {
return correlationId;
}
}
// Fall back to MDC to support beadledom-jaxrs 1.0. Retrieving from the headers is preferred.
correlationId = MDC.get(mdcName);
return correlationId;
}
示例2: ErrorResponse
import org.slf4j.MDC; //導入方法依賴的package包/類
/**
* Creates an error response with just the error code and description. The
* request ID will be taken from the MDC.
*
* @param error
* error code
* @param errorDescription
* error description
*/
public ErrorResponse(final String error,
final String errorDescription) {
this.error = error;
this.errorDescription = errorDescription;
requestId = MDC.get(REQUEST_ID);
cause = null;
errorClass = null;
host = MDC.get(MDCKeys.HOST);
jwtId = MDC.get(MDCKeys.JWT_ID);
stackTrace = null;
threadId = Thread.currentThread().getName();
requestUri = calculateRequestUri();
}
示例3: pushMDC
import org.slf4j.MDC; //導入方法依賴的package包/類
@Nonnull
public LogContext pushMDC(@Nonnull final String key, @Nullable final String value) {
if (mdcStack == null) {
mdcStack = new LinkedList<>();
}
final String old = MDC.get(key);
mdcStack.push(new MDCEntry(key, old));
MDC.put(key, value);
return this;
}
示例4: getProperty
import org.slf4j.MDC; //導入方法依賴的package包/類
public static String getProperty(IoSession session, String key) {
if (key == null) {
throw new IllegalArgumentException("key should not be null");
}
Map<String, String> context = getContext(session);
String answer = context.get(key);
if (answer != null) {
return answer;
}
return MDC.get(key);
}
示例5: calculateRequestUri
import org.slf4j.MDC; //導入方法依賴的package包/類
/**
* Performs a null-check on the request URI data.
*
* @return request URI
*/
private URI calculateRequestUri() {
final String requestUriString = MDC.get(MDCKeys.REQUEST_URI);
if (requestUriString == null) {
return null;
} else {
return URI.create(requestUriString);
}
}
示例6: handle
import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
for (Entry<String, String> e : mdcName2HeaderName.entrySet()) {
String mdcValue = MDC.get(e.getKey());
if (mdcValue != null) {
request.addHeader(new BasicHeader(e.getValue(), mdcValue));
}
}
}
開發者ID:Orange-OpenSource,項目名稱:orange-mathoms-logging,代碼行數:10,代碼來源:HttpRequestHandlerWithMdcPropagation.java
示例7: stopTestLogging
import org.slf4j.MDC; //導入方法依賴的package包/類
/**
* Removes the key (log file name) from MDC
*
* @return name of the log file, if one existed in MDC
*/
public static String stopTestLogging()
{
final String name = MDC.get(TEST_NAME);
MDC.remove(TEST_NAME);
return name;
}
示例8: log
import org.slf4j.MDC; //導入方法依賴的package包/類
/**
* Logs the HTTP status code and exception in HttpFSServer's log.
*
* @param status HTTP status code.
* @param throwable exception thrown.
*/
@Override
protected void log(Response.Status status, Throwable throwable) {
String method = MDC.get("method");
String path = MDC.get("path");
String message = getOneLineMessage(throwable);
AUDIT_LOG.warn("FAILED [{}:{}] response [{}] {}", new Object[]{method, path, status, message});
LOG.warn("[{}:{}] response [{}] {}", new Object[]{method, path, status, message}, throwable);
}
示例9: filter
import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
String requestId = MDC.get(Constants.X_OBOS_REQUEST_ID);
if (requestId != null) {
requestContext.getHeaders().putSingle(Constants.X_OBOS_REQUEST_ID, requestId);
}
}
示例10: getRid
import org.slf4j.MDC; //導入方法依賴的package包/類
public static String getRid() {
return MDC.get(RID);
}
示例11: getTimeNs
import org.slf4j.MDC; //導入方法依賴的package包/類
public static long getTimeNs(String key) {
String time = MDC.get(key + TIME);
return StringUtils.isNotBlank(time) ? Long.parseLong(time) : 0L;
}
示例12: getRequestId
import org.slf4j.MDC; //導入方法依賴的package包/類
private String getRequestId() {
String requestId = MDC.get(REQUEST_ID_MDC_KEY);
LOG.debug("'X-Request-Id' sent {}", requestId);
return requestId;
}
示例13: run
import org.slf4j.MDC; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Map<Method, Set<Invocation>> run(String patientClassPath, Artifact patient)
throws IOException, InterruptedException, AnalysisRunFailedException, ClassNotFoundException {
// create temporary file for output
Path analysisOutput = Files.createTempFile("kowalski-call-graph-batch-analysis-runner-", ".dat");
// TODO use G.reset() instead of fork and serialize, make sure only one
// job runs, start multiple job-vms
try {
// TODO jmx, arguments should be escaped
// -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044
// run command
String command = String.format(
"%s -Xmx2g -classpath %s %s -output-format none -allow-phantom-refs -p jb use-original-names --keep-line-number --process-dir %s --soot-class-path %s %s",
this.java, this.classPath, this.mainClass, patient.getFile().getAbsolutePath(), patientClassPath,
analysisOutput.toAbsolutePath().toString());
Process process = Runtime.getRuntime().exec(command);
String mdcPatient = MDC.get(Reader.PATIENT);
this.pipe(mdcPatient, process.getInputStream(), LOGGER::debug);
this.pipe(mdcPatient, process.getErrorStream(), LOGGER::warn);
if (!process.waitFor(this.timeout, TimeUnit.MILLISECONDS)) {
LOGGER.error("Killing analysis, took too long");
process.destroyForcibly();
}
// wait and check exit value
int exitValue = process.waitFor();
if (exitValue != 0) {
throw new AnalysisRunFailedException(exitValue, patient);
}
// deserialize output
try (Input input = new Input(Files.newInputStream(analysisOutput))) {
return (Map<Method, Set<Invocation>>) (new Kryo()).readObject(input,
(new TypeToken<HashMap<Method, HashSet<Invocation>>>() {
private static final long serialVersionUID = 1L;
}).getRawType());
}
} finally {
// delete temporary file
analysisOutput.toFile().delete();
}
}
示例14: getSessionId
import org.slf4j.MDC; //導入方法依賴的package包/類
public static String getSessionId() {
return MDC.get(FIELD_SESSION_ID);
}
示例15: getRootRequestId
import org.slf4j.MDC; //導入方法依賴的package包/類
public static String getRootRequestId() {
return MDC.get(FIELD_ROOT_REQUEST_ID);
}