本文整理汇总了Java中org.apache.logging.log4j.Logger类的典型用法代码示例。如果您正苦于以下问题:Java Logger类的具体用法?Java Logger怎么用?Java Logger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Logger类属于org.apache.logging.log4j包,在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
@Test
public void test() {
{
Logger logger = LogManager.getLogger("test.logger");
logger.error("This is an error!");
logger.error("This is another error!");
logger.error("This is a third error!");
}
assertThat(collector.getLogs()).hasSize(3)
.contains("This is an error!", "This is another error!", "This is a third error!");
List<LogEvent> rawLogs = (List<LogEvent>) collector.getRawLogs();
assertThat(rawLogs).hasSize(3);
assertTrue(rawLogs.stream().allMatch(l -> l.getLevel() == Level.ERROR));
}
示例2: WritePrimaryResult
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
public WritePrimaryResult(ReplicaRequest request, @Nullable Response finalResponse,
@Nullable Location location, @Nullable Exception operationFailure,
IndexShard primary, Logger logger) {
super(request, finalResponse, operationFailure);
this.location = location;
assert location == null || operationFailure == null
: "expected either failure to be null or translog location to be null, " +
"but found: [" + location + "] translog location and [" + operationFailure + "] failure";
if (operationFailure != null) {
this.finishedAsyncActions = true;
} else {
/*
* We call this before replication because this might wait for a refresh and that can take a while.
* This way we wait for the refresh in parallel on the primary and on the replica.
*/
new AsyncAfterWriteAction(primary, request, location, this, logger).run();
}
}
示例3: handleDiscord4JException
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
public static void handleDiscord4JException(@NotNull Logger logger, @NotNull Exception e, @NotNull ICommand commandHandler, @NotNull IMessage message) {
try {
logger.error("{} failed to handle command, a {} was captured",
() -> commandHandler.getClass().getSimpleName(),
() -> e.getClass().getSimpleName());
logger.error(e);
if (e instanceof MissingPermissionsException) {
messageDeletionService().schedule(getMessageBuilder(message)
.appendContent(message.getAuthor().mention())
.appendContent(" I dont have the necessary permissions to execute that action,")
.appendContent(" please give me the following permissions and try again")
.appendContent(System.lineSeparator())
.appendContent(((MissingPermissionsException) e).getMissingPermissions().toString())
.send());
}
} catch (@NotNull RateLimitException | DiscordException | MissingPermissionsException e1) {
logger.error(e1);
}
}
示例4: shouldIgnoreOrRejectNewClusterState
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
/**
* In the case we follow an elected master the new cluster state needs to have the same elected master and
* the new cluster state version needs to be equal or higher than our cluster state version.
* If the first condition fails we reject the cluster state and throw an error.
* If the second condition fails we ignore the cluster state.
*/
public static boolean shouldIgnoreOrRejectNewClusterState(Logger logger, ClusterState currentState, ClusterState newClusterState) {
validateStateIsFromCurrentMaster(logger, currentState.nodes(), newClusterState);
// reject cluster states that are not new from the same master
if (currentState.supersedes(newClusterState) ||
(newClusterState.nodes().getMasterNodeId().equals(currentState.nodes().getMasterNodeId()) && currentState.version() == newClusterState.version())) {
// if the new state has a smaller version, and it has the same master node, then no need to process it
logger.debug("received a cluster state that is not newer than the current one, ignoring (received {}, current {})", newClusterState.version(), currentState.version());
return true;
}
// reject older cluster states if we are following a master
if (currentState.nodes().getMasterNodeId() != null && newClusterState.version() < currentState.version()) {
logger.debug("received a cluster state that has a lower version than the current one, ignoring (received {}, current {})", newClusterState.version(), currentState.version());
return true;
}
return false;
}
示例5: filterPingResponses
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
static List<ZenPing.PingResponse> filterPingResponses(List<ZenPing.PingResponse> fullPingResponses, boolean masterElectionIgnoreNonMasters, Logger logger) {
List<ZenPing.PingResponse> pingResponses;
if (masterElectionIgnoreNonMasters) {
pingResponses = fullPingResponses.stream().filter(ping -> ping.node().isMasterNode()).collect(Collectors.toList());
} else {
pingResponses = fullPingResponses;
}
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
if (pingResponses.isEmpty()) {
sb.append(" {none}");
} else {
for (ZenPing.PingResponse pingResponse : pingResponses) {
sb.append("\n\t--> ").append(pingResponse);
}
}
logger.debug("filtered ping responses: (ignore_non_masters [{}]){}", masterElectionIgnoreNonMasters, sb);
}
return pingResponses;
}
示例6: handleResourceManager
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
/**
* Registers domains to resource manager from resource listeners.
* @param novousLogger
*/
private static void handleResourceManager(Logger novousLogger) {
novousLogger.info("Registering resource manager test...");
ResourceLinker.REGISTERED_RESOURCE_LINKERS.add(new TestResourceLinker());
novousLogger.info("Registering abstract resource linked manager...");
PairedRegistry<String, FallbackResourceManager> resourceManagerRegistry =
(PairedRegistry<String, FallbackResourceManager>) Minecraft
.getMinecraft().getResourceManager();
for (ResourceLinker linker : ResourceLinker.REGISTERED_RESOURCE_LINKERS) {
linker.getLinkedDomains().forEach((domain) -> resourceManagerRegistry.register
(domain, new
LinkedResourceManager()));
}
novousLogger.info("Testing resource linked manager...");
TestResourceLinker.checkTestSuccess();
}
示例7: func_181617_a
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
public static <V> V func_181617_a(FutureTask<V> p_181617_0_, Logger p_181617_1_)
{
try
{
p_181617_0_.run();
return p_181617_0_.get();
}
catch (ExecutionException executionexception)
{
p_181617_1_.fatal((String)"Error executing task", (Throwable)executionexception);
}
catch (InterruptedException interruptedexception)
{
p_181617_1_.fatal((String)"Error executing task", (Throwable)interruptedexception);
}
return (V)null;
}
示例8: runTask
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
@Nullable
public static <V> V runTask(FutureTask<V> task, Logger logger)
{
try
{
task.run();
return task.get();
}
catch (ExecutionException executionexception)
{
logger.fatal((String)"Error executing task", (Throwable)executionexception);
}
catch (InterruptedException interruptedexception)
{
logger.fatal((String)"Error executing task", (Throwable)interruptedexception);
}
return (V)null;
}
示例9: test03
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
@Test
public void test03() {
// Logger logger = LogManager.getFormatterLogger();
Logger logger = LogManager.getLogger();
String name = "李志伟";
Date birthday = new Date();
logger.debug("用户名称:[{}], 日期:[{}]", name, birthday);
logger.info("用户名称:[{}], 日期:[{}]", name, birthday);
logger.warn("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("用户名称:[{}], 日期:[{}]", name, birthday);
logger.fatal("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("异常信息提示", new RuntimeException("异常信息"));
LogManager.shutdown();
}
示例10: logGcOverhead
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
static void logGcOverhead(
final Logger logger,
final JvmMonitor.Threshold threshold,
final long current,
final long elapsed,
final long seq) {
switch (threshold) {
case WARN:
if (logger.isWarnEnabled()) {
logger.warn(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
case INFO:
if (logger.isInfoEnabled()) {
logger.info(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
case DEBUG:
if (logger.isDebugEnabled()) {
logger.debug(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
}
}
示例11: AbstractSearchAsyncAction
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
protected AbstractSearchAsyncAction(String name, Logger logger, SearchTransportService searchTransportService,
Function<String, Transport.Connection> nodeIdToConnection,
Map<String, AliasFilter> aliasFilter, Map<String, Float> concreteIndexBoosts,
Executor executor, SearchRequest request,
ActionListener<SearchResponse> listener, GroupShardsIterator shardsIts, long startTime,
long clusterStateVersion, SearchTask task, SearchPhaseResults<Result> resultConsumer) {
super(name, request, shardsIts, logger);
this.startTime = startTime;
this.logger = logger;
this.searchTransportService = searchTransportService;
this.executor = executor;
this.request = request;
this.task = task;
this.listener = listener;
this.nodeIdToConnection = nodeIdToConnection;
this.clusterStateVersion = clusterStateVersion;
this.concreteIndexBoosts = concreteIndexBoosts;
this.aliasFilter = aliasFilter;
this.results = resultConsumer;
}
示例12: createPerformanceLogger
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
@Override
protected PerformanceLogger createPerformanceLogger() throws IOException {
final Logger logger = createLogger();
final PerformanceLogger perfLogger = new PerformanceLogger() {
@Override
public void log(String message) {
logger.info(message);
}
@Override
public boolean isEnabled() {
return logger.isEnabled(Level.INFO);
}
};
return perfLogger;
}
示例13: logCrashedMemberWeights
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
/**
* logs the weight of failed members wrt the given previous view
*/
public void logCrashedMemberWeights(NetView oldView, Logger log) {
InternalDistributedMember lead = oldView.getLeadMember();
for (InternalDistributedMember mbr : this.crashedMembers) {
if (!oldView.contains(mbr)) {
continue;
}
int mbrWeight = mbr.getNetMember().getMemberWeight();
switch (mbr.getVmKind()) {
case DistributionManager.NORMAL_DM_TYPE:
if (lead != null && mbr.equals(lead)) {
mbrWeight += 15;
} else {
mbrWeight += 10;
}
break;
case DistributionManager.LOCATOR_DM_TYPE:
mbrWeight += 3;
break;
case DistributionManager.ADMIN_ONLY_DM_TYPE:
break;
default:
throw new IllegalStateException("Unknown member type: " + mbr.getVmKind());
}
log.info(" " + mbr + " had a weight of " + mbrWeight);
}
}
示例14: debug
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
public static void debug(Class<?> clazz, String msg, Object... args) {
final Logger logger = LogManager.getLogger(clazz);
if (logger.isDebugEnabled()) {
logger.debug(msg, args);
}
}
示例15: SearchDfsQueryThenFetchAsyncAction
import org.apache.logging.log4j.Logger; //导入依赖的package包/类
SearchDfsQueryThenFetchAsyncAction(Logger logger, SearchTransportService searchTransportService,
Function<String, Transport.Connection> nodeIdToConnection,
Map<String, AliasFilter> aliasFilter, Map<String, Float> concreteIndexBoosts,
SearchPhaseController searchPhaseController, Executor executor, SearchRequest request,
ActionListener<SearchResponse> listener, GroupShardsIterator shardsIts, long startTime,
long clusterStateVersion, SearchTask task) {
super("dfs", logger, searchTransportService, nodeIdToConnection, aliasFilter, concreteIndexBoosts, executor,
request, listener, shardsIts, startTime, clusterStateVersion, task, new SearchPhaseResults<>(shardsIts.size()));
this.searchPhaseController = searchPhaseController;
}