本文整理匯總了Java中org.apache.logging.log4j.core.LogEvent.getThreadName方法的典型用法代碼示例。如果您正苦於以下問題:Java LogEvent.getThreadName方法的具體用法?Java LogEvent.getThreadName怎麽用?Java LogEvent.getThreadName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.LogEvent
的用法示例。
在下文中一共展示了LogEvent.getThreadName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lookup
import org.apache.logging.log4j.core.LogEvent; //導入方法依賴的package包/類
@Override
public String lookup(LogEvent event, String key) {
return event.getThreadName() == null ? Thread.currentThread().getName() : event.getThreadName();
}
示例2: append
import org.apache.logging.log4j.core.LogEvent; //導入方法依賴的package包/類
/**
* This method is optimized with the assumption that at least one listener has set a level which
* requires that the event be sent. This is ensured by modifying the appender's configuration
* whenever a listener is added or removed.
*/
@Override
public void append(final LogEvent event) {
if (this.alertingDisabled) {
return;
}
// If already appending then don't send to avoid infinite recursion
if ((alerting.get())) {
return;
}
setIsAlerting(true);
try {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("Delivering an alert event: {}", event);
}
InternalDistributedSystem ds = this.systemRef.get();
if (ds == null) {
// Use info level to avoid triggering another alert
logger.info("Did not append alert event because the distributed system is set to null.");
return;
}
DistributionManager distMgr = (DistributionManager) ds.getDistributionManager();
final int intLevel = logLevelToAlertLevel(event.getLevel().intLevel());
final Date date = new Date(event.getTimeMillis());
final String threadName = event.getThreadName();
final String logMessage = event.getMessage().getFormattedMessage();
final String stackTrace = ThreadUtils.stackTraceToString(event.getThrown(), true);
final String connectionName = ds.getConfig().getName();
for (Listener listener : this.listeners) {
if (event.getLevel().intLevel() > listener.getLevel().intLevel()) {
break;
}
try {
AlertListenerMessage alertMessage =
AlertListenerMessage.create(listener.getMember(), intLevel, date, connectionName,
threadName, Thread.currentThread().getId(), logMessage, stackTrace);
if (listener.getMember().equals(distMgr.getDistributionManagerId())) {
if (isDebugEnabled) {
logger.debug("Delivering local alert message: {}, {}, {}, {}, {}, [{}], [{}].",
listener.getMember(), intLevel, date, connectionName, threadName, logMessage,
stackTrace);
}
alertMessage.process(distMgr);
} else {
if (isDebugEnabled) {
logger.debug("Delivering remote alert message: {}, {}, {}, {}, {}, [{}], [{}].",
listener.getMember(), intLevel, date, connectionName, threadName, logMessage,
stackTrace);
}
distMgr.putOutgoing(alertMessage);
}
} catch (ReenteredConnectException e) {
// OK. We can't send to this recipient because we're in the middle of
// trying to connect to it.
}
}
} finally {
setIsAlerting(false);
}
}
示例3: resolve
import org.apache.logging.log4j.core.LogEvent; //導入方法依賴的package包/類
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
String threadName = logEvent.getThreadName();
return new TextNode(threadName);
}