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

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

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

Logger.error介绍

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

代码示例

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

  1. @Override
  2. public void success(String type, Tuple<Long, Settings> settings) {
  3. if(latch.getCount() <= 0) {
  4. log.error("Latch already counted down (for {} of {}) (index={})", type, Arrays.toString(events), searchguardIndex);
  5. }
  6. rs.put(type, settings);
  7. latch.countDown();
  8. if(log.isDebugEnabled()) {
  9. log.debug("Received config for {} (of {}) with current latch value={}", type, Arrays.toString(events), latch.getCount());
  10. }
  11. }

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

  1. private List<String> walkFileTree(List<String> files, Path path) {
  2. if (Files.isRegularFile(path)) {
  3. files.add(path.toString());
  4. } else if (Files.isDirectory(path)) try {
  5. Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
  6. @Override
  7. public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
  8. files.add(file.toString());
  9. return FileVisitResult.CONTINUE;
  10. }
  11. @Override
  12. public FileVisitResult visitFileFailed(Path file, IOException e) {
  13. logger.error("[Ext Loading] listing files", e);
  14. return FileVisitResult.CONTINUE;
  15. }
  16. });
  17. } catch (IOException e) {
  18. logger.error("[Ext Loading] listing files", e);
  19. } else {
  20. logger.warn("[Ext Loading] file not found: " + path);
  21. }
  22. return files;
  23. }

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

  1. public boolean deleteUser(UserKey userKey) {
  2. int removed = 0;
  3. try (Connection connection = ds.getConnection();
  4. PreparedStatement ps = connection.prepareStatement(deleteUser)) {
  5. ps.setString(1, userKey.email);
  6. ps.setString(2, userKey.appName);
  7. removed = ps.executeUpdate();
  8. connection.commit();
  9. } catch (Exception e) {
  10. log.error("Error removing user {} from DB.", userKey, e);
  11. }
  12. return removed > 0;
  13. }
  14. }

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

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

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

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

代码示例来源:origin: DSpace/DSpace

  1. statement = connection.prepareStatement(sequenceSQL);
  2. statement.setString(1, sequenceName);
  3. if (schemaFilter) {
  4. statement.setString(2, schema);
  5. log.error("Error attempting to determine if sequence " + sequenceName + " exists", e);
  6. } finally {
  7. try {
  8. statement.close();

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

  1. public FullHttpResponse invoke(Object[] params) {
  2. try {
  3. mark();
  4. return (FullHttpResponse) classMethod.invoke(handler, params);
  5. } catch (Exception e) {
  6. Throwable cause = e.getCause();
  7. if (cause == null) {
  8. log.error("Error invoking handler. Reason : {}.", e.getMessage());
  9. log.debug(e);
  10. } else {
  11. log.error("Error invoking handler. Reason : {}.", cause.getMessage());
  12. log.debug(cause);
  13. }
  14. return Response.serverError(e.getMessage());
  15. }
  16. }

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

  1. public String selectHostByToken(String token) {
  2. try (Connection connection = ds.getConnection();
  3. PreparedStatement statement = connection.prepareStatement(selectHostByToken)) {
  4. statement.setString(1, token);
  5. try (ResultSet rs = statement.executeQuery()) {
  6. connection.commit();
  7. if (rs.next()) {
  8. return rs.getString("host");
  9. }
  10. }
  11. } catch (Exception e) {
  12. log.error("Error getting token host. Reason : {}", e.getMessage());
  13. }
  14. return null;
  15. }

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

  1. @Override
  2. public void onDisconnect(InternalDistributedSystem sys) {
  3. if (logger.isDebugEnabled()) {
  4. this.logger.debug("Calling AdminDistributedSystemJmxImpl#onDisconnect");
  5. this.mbeanName, notificationSequenceNumber.addAndGet(1), null));
  6. } catch (MBeanException e) {
  7. logger.warn(e.getMessage(), e);
  8. logger.warn(e.getMessage(), e);
  9. throw e;
  10. } catch (VirtualMachineError err) {
  11. logger.error(e.getMessage(), e);
  12. throw e;
  13. if (logger.isDebugEnabled()) {
  14. this.logger.debug("Completed AdminDistributedSystemJmxImpl#onDisconnect");

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

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

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

  1. @Override
  2. public void success(String id, Tuple<Long, Settings> settings) {
  3. if(latch.getCount() <= 0) {
  4. log.error("Latch already counted down (for {} of {}) (index={})", id, Arrays.toString(events), searchguardIndex);
  5. }
  6. rs.put(id, settings);
  7. latch.countDown();
  8. if(log.isDebugEnabled()) {
  9. log.debug("Received config for {} (of {}) with current latch value={}", id, Arrays.toString(events), latch.getCount());
  10. }
  11. }

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

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

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

  1. protected void processEventorAndWebhook(User user, DashBoard dash, int deviceId, Session session, short pin,
  2. PinType pinType, String value, long now) {
  3. try {
  4. eventorProcessor.process(user, session, dash, deviceId, pin, pinType, value, now);
  5. webhookProcessor.process(session, dash, deviceId, pin, pinType, value, now);
  6. } catch (QuotaLimitException qle) {
  7. log.debug("User {} reached notification limit for eventor/webhook.", user.name);
  8. } catch (IllegalArgumentException iae) {
  9. log.debug("Error processing webhook for {}. Reason : {}", user.email, iae.getMessage());
  10. } catch (Exception e) {
  11. log.error("Error processing eventor/webhook.", e);
  12. }
  13. }

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

  1. public boolean insertTokenHost(String token, String host, String email, int dashId, int deviceId) {
  2. try (Connection connection = ds.getConnection();
  3. PreparedStatement ps = connection.prepareStatement(insertTokenHostProject)) {
  4. ps.setString(1, token);
  5. ps.setString(2, host);
  6. ps.setString(3, email);
  7. ps.setInt(4, dashId);
  8. ps.setInt(5, deviceId);
  9. ps.executeUpdate();
  10. connection.commit();
  11. return true;
  12. } catch (Exception e) {
  13. log.error("Error insert token host. Reason : {}", e.getMessage());
  14. }
  15. return false;
  16. }

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

  1. @Override
  2. public void disconnect() {
  3. try {
  4. super.disconnect();
  5. // Save existing StatAlert Definitions
  6. saveAlertDefinitionsAsSerializedObjects();
  7. /* Remove Cache Listener to listen to Cache & Region create/destroy events */
  8. if (logger.isDebugEnabled()) {
  9. logger.debug("Removing CacheAndRegionListener .... ");
  10. }
  11. removeCacheListener(cacheRegionListener);
  12. } catch (RuntimeException e) {
  13. logger.warn(e.getMessage(), e);
  14. throw e;
  15. } catch (VirtualMachineError err) {
  16. SystemFailure.initiateFailure(err);
  17. // If this ever returns, re-throw the error. We're poisoned
  18. // now, so don't let this thread continue.
  19. throw err;
  20. } catch (Error e) {
  21. // Whenever you catch Error or Throwable, you must also
  22. // catch VirtualMachineError (see above). However, there is
  23. // _still_ a possibility that you are dealing with a cascading
  24. // error condition, so you also need to check to see if the JVM
  25. // is still usable:
  26. SystemFailure.checkFailure();
  27. logger.error(e.getMessage(), e);
  28. throw e;
  29. }
  30. }

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

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

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

  1. private Function newFunction(final Class<Function> clazz, final boolean errorOnNoSuchMethod) {
  2. try {
  3. final Constructor<Function> constructor = clazz.getConstructor();
  4. return constructor.newInstance();
  5. } catch (NoSuchMethodException nsmex) {
  6. if (errorOnNoSuchMethod) {
  7. logger.error("Zero-arg constructor is required, but not found for class: {}",
  8. clazz.getName(), nsmex);
  9. } else {
  10. if (logger.isDebugEnabled()) {
  11. logger.debug(
  12. "Not registering function because it doesn't have a zero-arg constructor: {}",
  13. clazz.getName());
  14. }
  15. }
  16. } catch (Exception ex) {
  17. logger.error("Error when attempting constructor for function for class: {}", clazz.getName(),
  18. ex);
  19. }
  20. return null;
  21. }

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

  1. private void addZipEntryAndWrite(ZipOutputStream zipStream,
  2. String onePinFileName, byte[] onePinDataCsv) throws IOException {
  3. ZipEntry zipEntry = new ZipEntry(onePinFileName);
  4. try {
  5. zipStream.putNextEntry(zipEntry);
  6. zipStream.write(onePinDataCsv);
  7. zipStream.closeEntry();
  8. } catch (ZipException zipException) {
  9. String message = zipException.getMessage();
  10. if (message != null && message.contains("duplicate")) {
  11. log.warn("Duplicate zip entry {}. Wrong report configuration.", onePinFileName);
  12. } else {
  13. log.error("Error compressing report file.", message);
  14. throw zipException;
  15. }
  16. } catch (IOException e) {
  17. log.error("Error compressing report file.", e.getMessage());
  18. throw e;
  19. }
  20. }

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

  1. public static DashBoard deepCopy(DashBoard dash) {
  2. if (dash == null) {
  3. return null;
  4. }
  5. try {
  6. TokenBuffer tb = new TokenBuffer(JsonParser.MAPPER, false);
  7. JsonParser.MAPPER.writeValue(tb, dash);
  8. return JsonParser.MAPPER.readValue(tb.asParser(), DashBoard.class);
  9. } catch (Exception e) {
  10. log.error("Error during deep copy of dashboard. Reason : {}", e.getMessage());
  11. log.debug(e);
  12. }
  13. return null;
  14. }

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

  1. public String getUserServerIp(String email, String appName) {
  2. String ip = null;
  3. try (Connection connection = ds.getConnection();
  4. PreparedStatement statement = connection.prepareStatement(selectIpForUser)) {
  5. statement.setString(1, email);
  6. statement.setString(2, appName);
  7. try (ResultSet rs = statement.executeQuery()) {
  8. while (rs.next()) {
  9. ip = rs.getString("ip");
  10. }
  11. connection.commit();
  12. }
  13. } catch (Exception e) {
  14. log.error("Error getting user server ip. {}-{}. Reason : {}", email, appName, e.getMessage());
  15. }
  16. return ip;
  17. }

相关文章