本文整理汇总了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);
}