org.apache.logging.log4j.Logger.warn()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中org.apache.logging.log4j.Logger.warn()方法的一些代码示例,展示了Logger.warn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger.warn()方法的具体详情如下:
包路径:org.apache.logging.log4j.Logger
类名称:Logger
方法名:warn

Logger.warn介绍

[英]Logs a message CharSequence with the Level#WARN level.
[中]记录级别为#警告级别的消息字符序列。

代码示例

代码示例来源:origin: blynkkk/blynk-server

private static void logError(String errorMessage, String email) {
  if (errorMessage != null) {
    if (errorMessage.contains("Status is a duplicate")) {
      log.warn("Duplicate twit status for user {}.", email);
    } else if (errorMessage.contains("Authentication credentials")) {
      log.warn("Tweet authentication failure for {}.", email);
    } else if (errorMessage.contains("The request is understood, but it has been refused.")) {
      log.warn("User twit account is banned by twitter. {}.", email);
    } else {
      log.error("Error sending twit for user {}. Reason : {}", email, errorMessage);
    }
  }
}

代码示例来源:origin: apache/geode

private static void releasePRIDLock(final DistributedLockService lockService) {
 try {
  lockService.unlock(PartitionedRegionHelper.MAX_PARTITIONED_REGION_ID);
  if (logger.isDebugEnabled()) {
   logger.debug("releasePRIDLock: Released the dlock in allPartitionedRegions for {}",
     PartitionedRegionHelper.MAX_PARTITIONED_REGION_ID);
  }
 } catch (Exception es) {
  logger.warn(String.format("releasePRIDLock: unlocking %s caught an exception",
    Integer.valueOf(PartitionedRegionHelper.MAX_PARTITIONED_REGION_ID)),
    es);
 }
}

代码示例来源:origin: apache/geode

/**
 * Handle rejected execution for a function execution thread. Spin off a thread directly in
 * this case, since that means a function is executing another function. The child function
 * request shouldn't be in the queue behind the parent request since the parent function is
 * dependent on the child function executing.
 */
private void handleRejectedExecutionForFunctionExecutionThread(Runnable r,
  ThreadPoolExecutor executor) {
 if (logger.isDebugEnabled()) {
  logger.warn("An additional " + FUNCTION_EXECUTION_PROCESSOR_THREAD_PREFIX
    + " thread is being launched to prevent slow performance due to nested function executions");
 }
 launchAdditionalThread(r, executor);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

public static void main(final String[] args) {
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      "target/test-classes/log4j2-console-highlight-logback.xml")) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    LOG.error("Error message.", new IOException("test"));
  }
}

代码示例来源:origin: apache/geode

@Override
public void close(boolean keepAlive) {
 if (logger.isDebugEnabled()) {
  logger.debug("Shutting down connection manager with keepAlive {}", keepAlive);
   if (!this.loadConditioningProcessor.awaitTermination(PoolImpl.SHUTDOWN_TIMEOUT,
     TimeUnit.MILLISECONDS)) {
    logger.warn("Timeout waiting for load conditioning tasks to complete");
  logger.error("Error stopping loadConditioningProcessor", e);
 } catch (InterruptedException e) {
  logger.error(
    "Interrupted stopping loadConditioningProcessor",
    e);

代码示例来源:origin: apache/geode

void stopExecutor(ExecutorService executor) {
 if (executor == null) {
  return;
 }
 executor.shutdown();
 final int secToWait = Integer
   .getInteger(DistributionConfig.GEMFIRE_PREFIX + "prrecovery-close-timeout", 120).intValue();
 try {
  executor.awaitTermination(secToWait, TimeUnit.SECONDS);
 } catch (InterruptedException x) {
  Thread.currentThread().interrupt();
  logger.debug("Failed in interrupting the Resource Manager Thread due to interrupt");
 }
 if (!executor.isTerminated()) {
  logger.warn("Failed to stop resource manager threads in {} seconds",
    secToWait);
 }
}

代码示例来源:origin: floragunncom/search-guard

public static InterClusterRequestEvaluator instantiateInterClusterRequestEvaluator(final String clazz, final Settings settings) {
  try {
    final Class<?> clazz0 = Class.forName(clazz);
    final InterClusterRequestEvaluator ret = (InterClusterRequestEvaluator) clazz0.getConstructor(Settings.class).newInstance(settings);
    addLoadedModule(clazz0);
    return ret;
  } catch (final Throwable e) {
    log.warn("Unable to load inter cluster request evaluator '{}' due to {}", clazz, e.toString());
    if(log.isDebugEnabled()) {
      log.debug("Stacktrace: ",e);
    }
    return new DefaultInterClusterRequestEvaluator(settings);
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      "target/test-classes/log4j2-console-highlight-default.xml")) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    LOG.error("Error message.", new IOException("test"));
  }
}

代码示例来源:origin: medcl/elasticsearch-analysis-ik

private List<String> walkFileTree(List<String> files, Path path) {
  if (Files.isRegularFile(path)) {
    files.add(path.toString());
  } else if (Files.isDirectory(path)) try {
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
        files.add(file.toString());
        return FileVisitResult.CONTINUE;
      }
      @Override
      public FileVisitResult visitFileFailed(Path file, IOException e) {
        logger.error("[Ext Loading] listing files", e);
        return FileVisitResult.CONTINUE;
      }
    });
  } catch (IOException e) {
    logger.error("[Ext Loading] listing files", e);
  } else {
    logger.warn("[Ext Loading] file not found: " + path);
  }
  return files;
}

代码示例来源:origin: apache/geode

@Override
public void onDisconnect(InternalDistributedSystem sys) {
 if (logger.isDebugEnabled()) {
  this.logger.debug("Calling AdminDistributedSystemJmxImpl#onDisconnect");
     this.mbeanName, notificationSequenceNumber.addAndGet(1), null));
  } catch (MBeanException e) {
   logger.warn(e.getMessage(), e);
  logger.warn(e.getMessage(), e);
  throw e;
 } catch (VirtualMachineError err) {
  logger.error(e.getMessage(), e);
  throw e;
 if (logger.isDebugEnabled()) {
  this.logger.debug("Completed AdminDistributedSystemJmxImpl#onDisconnect");

代码示例来源:origin: org.apache.logging.log4j/log4j-api

private void loadProvider(final Bundle bundle) {
  if (bundle.getState() == Bundle.UNINSTALLED) {
    return;
  }
  try {
    checkPermission(new AdminPermission(bundle, AdminPermission.RESOURCE));
    checkPermission(new AdaptPermission(BundleWiring.class.getName(), bundle, AdaptPermission.ADAPT));
    final BundleContext bundleContext = bundle.getBundleContext();
    if (bundleContext == null) {
      LOGGER.debug("Bundle {} has no context (state={}), skipping loading provider", bundle.getSymbolicName(), toStateString(bundle.getState()));
    } else {
      loadProvider(bundleContext, bundle.adapt(BundleWiring.class));
    }
  } catch (final SecurityException e) {
    LOGGER.debug("Cannot access bundle [{}] contents. Ignoring.", bundle.getSymbolicName(), e);
  } catch (final Exception e) {
    LOGGER.warn("Problem checking bundle {} for Log4j 2 provider.", bundle.getSymbolicName(), e);
  }
}

代码示例来源:origin: apache/geode

@Override
 public void run2() {
  TXManagerImpl mgr = TXManagerImpl.currentInstance;
  TXStateProxy tx = mgr.suspendedTXs.remove(txId);
  if (tx != null) {
   try {
    if (logger.isDebugEnabled()) {
     logger.debug("TX: Expiry task rolling back transaction: {}", txId);
    }
    tx.rollback();
   } catch (GemFireException e) {
    logger.warn(String.format(
      "Exception occurred while rolling back timed out transaction %s", txId), e);
   }
  }
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      "target/test-classes/log4j2-console.xml")) {
    LOG.fatal("\u001b[1;35mFatal message.\u001b[0m");
    LOG.error("\u001b[1;31mError message.\u001b[0m");
    LOG.warn("\u001b[0;33mWarning message.\u001b[0m");
    LOG.info("\u001b[0;32mInformation message.\u001b[0m");
    LOG.debug("\u001b[0;36mDebug message.\u001b[0m");
    LOG.trace("\u001b[0;30mTrace message.\u001b[0m");
    LOG.error("\u001b[1;31mError message.\u001b[0m", new IOException("test"));
  }
}

代码示例来源:origin: blynkkk/blynk-server

private void addZipEntryAndWrite(ZipOutputStream zipStream,
                  String onePinFileName, byte[] onePinDataCsv) throws IOException {
  ZipEntry zipEntry = new ZipEntry(onePinFileName);
  try {
    zipStream.putNextEntry(zipEntry);
    zipStream.write(onePinDataCsv);
    zipStream.closeEntry();
  } catch (ZipException zipException) {
    String message = zipException.getMessage();
    if (message != null && message.contains("duplicate")) {
      log.warn("Duplicate zip entry {}. Wrong report configuration.", onePinFileName);
    } else {
      log.error("Error compressing report file.", message);
      throw zipException;
    }
  } catch (IOException e) {
    log.error("Error compressing report file.", e.getMessage());
    throw e;
  }
}

代码示例来源:origin: apache/geode

@Override
public void disconnect() {
 try {
  super.disconnect();
  // Save existing StatAlert Definitions
  saveAlertDefinitionsAsSerializedObjects();
  /* Remove Cache Listener to listen to Cache & Region create/destroy events */
  if (logger.isDebugEnabled()) {
   logger.debug("Removing CacheAndRegionListener .... ");
  }
  removeCacheListener(cacheRegionListener);
 } catch (RuntimeException e) {
  logger.warn(e.getMessage(), e);
  throw e;
 } catch (VirtualMachineError err) {
  SystemFailure.initiateFailure(err);
  // If this ever returns, re-throw the error. We're poisoned
  // now, so don't let this thread continue.
  throw err;
 } catch (Error e) {
  // Whenever you catch Error or Throwable, you must also
  // catch VirtualMachineError (see above). However, there is
  // _still_ a possibility that you are dealing with a cascading
  // error condition, so you also need to check to see if the JVM
  // is still usable:
  SystemFailure.checkFailure();
  logger.error(e.getMessage(), e);
  throw e;
 }
}

代码示例来源:origin: apache/geode

private void runUntilShutdown(Runnable r) {
 try {
  r.run();
 } catch (CancelException e) {
  if (logger.isTraceEnabled()) {
   logger.trace("Caught shutdown exception", e);
  }
 } catch (VirtualMachineError err) {
  SystemFailure.initiateFailure(err);
  // If this ever returns, rethrow the error. We're poisoned
  // now, so don't let this thread continue.
  throw err;
 } catch (Throwable t) {
  SystemFailure.checkFailure();
  if (isCloseInProgress()) {
   logger.debug("Caught unusual exception during shutdown: {}", t.getMessage(), t);
  } else {
   logger.warn("Task failed with exception", t);
  }
 }
}

代码示例来源:origin: floragunncom/search-guard

public static PrincipalExtractor instantiatePrincipalExtractor(final String clazz) {
  try {
    final Class<?> clazz0 = Class.forName(clazz);
    final PrincipalExtractor ret = (PrincipalExtractor) clazz0.newInstance();
    addLoadedModule(clazz0);
    return ret;
  } catch (final Throwable e) {
    log.warn("Unable to load pricipal extractor '{}' due to {}", clazz, e.toString());
    if(log.isDebugEnabled()) {
      log.debug("Stacktrace: ",e);
    }
    return new DefaultPrincipalExtractor();
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      "target/test-classes/log4j2-console-style-name-ansi.xml")) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    LOG.error("Error message.", new IOException("test"));
  }
}

代码示例来源:origin: blynkkk/blynk-server

private static SslContext initSslContext(String serverCertPath, String serverKeyPath, String serverPass,
                    SslProvider sslProvider) {
  try {
    File serverCert = new File(serverCertPath);
    File serverKey = new File(serverKeyPath);
    if (!serverCert.exists() || !serverKey.exists()) {
      log.warn("ATTENTION. Server certificate paths (cert : '{}', key : '{}') not valid."
              + " Using embedded server certs and one way ssl. This is not secure."
              + " Please replace it with your own certs.",
          serverCert.getAbsolutePath(), serverKey.getAbsolutePath());
      return build(sslProvider);
    }
    return build(serverCert, serverKey, serverPass, sslProvider);
  } catch (CertificateException | SSLException | IllegalArgumentException e) {
    log.error("Error initializing ssl context. Reason : {}", e.getMessage());
    throw new RuntimeException(e.getMessage());
  }
}

代码示例来源:origin: apache/geode

if (logger.isDebugEnabled()) {
  logger.debug("Adding CacheAndRegionListener .... ");
 logger.warn(e.getMessage(), e);
 throw e;
} catch (VirtualMachineError err) {
 logger.error(e.getMessage(), e);
 throw e;

相关文章