本文整理汇总了Java中org.apache.logging.log4j.ThreadContext.put方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.put方法的具体用法?Java ThreadContext.put怎么用?Java ThreadContext.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.ThreadContext
的用法示例。
在下文中一共展示了ThreadContext.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例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: 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");
}
示例4: 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;
}
}
示例5: 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);
}
示例6: 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());
}
示例7: 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();
}
示例8: 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();
}
示例9: 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");
}
示例10: 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);
}
}
示例11: run
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void run() {
try {
boolean successful = false;
Thread.currentThread().setName( "FetchThread[" + source.sourceId() + "]" );
ThreadContext.put("sourceId", source.sourceId());
EventBusManager.fire( new SourceFetchStartedEvent( source.sourceId(), numRules, System.currentTimeMillis() ) );
successful = source.load( timestamp, now, handler );
EventBusManager.fire( new SourceFetchFinishedEvent( source.sourceId(), System.currentTimeMillis(), successful ) );
Thread.currentThread().setName( "FetchThread[none]" );
ThreadContext.put("sourceId", "[none]");
} catch ( Exception e ) {
log.warn( "A totally unexpected exception occured during single fetch: ", e );
}
}
示例12: run
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void run()
{
try
{
Thread.sleep(200);
}
catch (InterruptedException e)
{
}
if (details)
{
ThreadContext.put("key2", "value2");
ThreadContext.put("key4", "value4");
logger.error("Some message", new Exception("Error"));
ThreadContext.remove("key2");
ThreadContext.remove("key4");
}
else
{
logger.info("Hello World!");
}
}
示例13: testLookup
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testLookup() {
final Map<String, String> map = new HashMap<>();
map.put(TESTKEY, TESTVAL);
final StrLookup lookup = new Interpolator(new MapLookup(map));
ThreadContext.put(TESTKEY, TESTVAL);
String value = lookup.lookup(TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("ctx:" + TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("sys:" + TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("SYS:" + TESTKEY2);
assertEquals(TESTVAL, value);
value = lookup.lookup("BadKey");
assertNull(value);
ThreadContext.clearMap();
value = lookup.lookup("ctx:" + TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("jndi:" + TEST_CONTEXT_RESOURCE_NAME);
assertEquals(TEST_CONTEXT_NAME, value);
}
示例14: process
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
try {
String requestId = exchange.getProperty(RequestIdManager.REQUEST_ID, String.class);
ThreadContext.put(RequestIdManager.REQUEST_ID, requestId);
doProcess(exchange);
} finally {
ThreadContext.remove(RequestIdManager.REQUEST_ID);
}
}
示例15: setUpDirs
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void setUpDirs() {
TEMPDIR = FileUtil.findDirectory(getRunDir(), "temp");
INSTANCEDIR = FileUtil.findDirectory(getRunDir(), "instances");
LOGFILE = FileUtil.findDirectory(getRunDir(), "logs");
ICONDIR = FileUtil.findDirectory(Constants.TEMPDIR, "images");
MINECRAFTDIR = FileUtil.findDirectory(getRunDir(), "minecraft");
EXPORTS = FileUtil.findDirectory(getRunDir(), "exports");
MODPACKICON = new File(getRunDir(), "modpack.png");
ThreadContext.put("logs", LOGFILE.toString());
OneClientLogging.init();
}