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

x33g5p2x  于2022-01-16 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(939)

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

Logger.error介绍

[英]Log a message at the ERROR level.
[中]在错误级别记录消息。

代码示例

代码示例来源:origin: iluwatar/java-design-patterns

  1. /**
  2. * Stops logging clients. This is a blocking call.
  3. */
  4. public void stop() {
  5. service.shutdown();
  6. if (!service.isTerminated()) {
  7. service.shutdownNow();
  8. try {
  9. service.awaitTermination(1000, TimeUnit.SECONDS);
  10. } catch (InterruptedException e) {
  11. LOGGER.error("exception awaiting termination", e);
  12. }
  13. }
  14. LOGGER.info("Logging clients stopped");
  15. }

代码示例来源:origin: ctripcorp/apollo

  1. @Override
  2. @SuppressWarnings("unchecked")
  3. public <T extends Provider> T provider(Class<T> clazz) {
  4. Provider provider = m_providers.get(clazz);
  5. if (provider != null) {
  6. return (T) provider;
  7. } else {
  8. logger.error("No provider [{}] found in DefaultProviderManager, please make sure it is registered in DefaultProviderManager ",
  9. clazz.getName());
  10. return (T) NullProviderManager.provider;
  11. }
  12. }

代码示例来源:origin: skylot/jadx

  1. public static void setClipboardString(String text) {
  2. try {
  3. Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  4. Transferable transferable = new StringSelection(text);
  5. clipboard.setContents(transferable, null);
  6. LOG.debug("String '{}' copied to clipboard", text);
  7. } catch (Exception e) {
  8. LOG.error("Failed copy string '{}' to clipboard", text, e);
  9. }
  10. }
  11. }

代码示例来源:origin: alibaba/canal

  1. private void notifyStart(File instanceDir, String destination, File[] instanceConfigs) {
  2. try {
  3. defaultAction.start(destination);
  4. actions.put(destination, defaultAction);
  5. // 启动成功后记录配置文件信息
  6. InstanceConfigFiles lastFile = lastFiles.get(destination);
  7. List<FileInfo> newFileInfo = new ArrayList<FileInfo>();
  8. for (File instanceConfig : instanceConfigs) {
  9. newFileInfo.add(new FileInfo(instanceConfig.getName(), instanceConfig.lastModified()));
  10. }
  11. lastFile.setInstanceFiles(newFileInfo);
  12. logger.info("auto notify start {} successful.", destination);
  13. } catch (Throwable e) {
  14. logger.error(String.format("scan add found[%s] but start failed", destination), e);
  15. }
  16. }

代码示例来源:origin: Netflix/eureka

  1. private List<String> toDomains(List<String> ec2Urls) {
  2. List<String> domains = new ArrayList<>(ec2Urls.size());
  3. for(String url : ec2Urls) {
  4. try {
  5. domains.add(extractDomain(url));
  6. } catch(MalformedURLException e) {
  7. logger.error("Invalid url {}", url, e);
  8. }
  9. }
  10. return domains;
  11. }

代码示例来源:origin: ctripcorp/apollo

  1. private void handleEnvDown(Env env) {
  2. int failedTimes = healthCheckFailedCounter.get(env);
  3. healthCheckFailedCounter.put(env, ++failedTimes);
  4. if (!envStatusMark.get(env)) {
  5. logger.error("Env is down. env: {}, failed times: {}, meta server address: {}", env, failedTimes,
  6. MetaDomainConsts.getDomain(env));
  7. } else {
  8. if (failedTimes >= ENV_DOWN_THRESHOLD) {
  9. envStatusMark.put(env, false);
  10. logger.error("Env is down because health check failed for {} times, "
  11. + "which equals to down threshold. env: {}, meta server address: {}", ENV_DOWN_THRESHOLD, env,
  12. MetaDomainConsts.getDomain(env));
  13. } else {
  14. logger.error(
  15. "Env health check failed for {} times which less than down threshold. down threshold:{}, env: {}, meta server address: {}",
  16. failedTimes, ENV_DOWN_THRESHOLD, env, MetaDomainConsts.getDomain(env));
  17. }
  18. }
  19. }

代码示例来源:origin: Graylog2/graylog2-server

  1. @Override
  2. public void onEvent(RawMessageEvent event, long sequence, boolean endOfBatch) throws Exception {
  3. batch.add(event);
  4. log.debug("End of batch, journalling {} messages", batch.size());
  5. writeToJournal(converter, entries);
  6. } catch (Exception e) {
  7. log.error("Unable to write to journal - retrying", e);

代码示例来源:origin: alibaba/nacos

  1. static public List<String> checkMd5() {
  2. List<String> diffList = new ArrayList<String>();
  3. long startTime = System.currentTimeMillis();
  4. for (Entry<String/* groupKey */, CacheItem> entry : CACHE.entrySet()) {
  5. String groupKey = entry.getKey();
  6. String[] dg = GroupKey.parseKey(groupKey);
  7. String dataId = dg[0];
  8. String group = dg[1];
  9. String tenant = dg[2];
  10. try {
  11. String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
  12. if (!entry.getValue().md5.equals(loacalMd5)) {
  13. defaultLog.warn("[md5-different] dataId:{},group:{}",
  14. dataId, group);
  15. diffList.add(groupKey);
  16. }
  17. } catch (IOException e) {
  18. defaultLog.error("getLocalConfigMd5 fail,dataId:{},group:{}",
  19. dataId, group);
  20. }
  21. }
  22. long endTime = System.currentTimeMillis();
  23. defaultLog.warn("checkMd5 cost:{}; diffCount:{}", endTime - startTime,
  24. diffList.size());
  25. return diffList;
  26. }

代码示例来源:origin: Netflix/eureka

  1. private List<AwsEndpoint> getClusterEndpointsFromConfig() {
  2. String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
  3. String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
  4. Map<String, List<String>> serviceUrls = EndpointUtils
  5. .getServiceUrlsMapFromConfig(clientConfig, myZone, clientConfig.shouldPreferSameZoneEureka());
  6. List<AwsEndpoint> endpoints = new ArrayList<>();
  7. for (String zone : serviceUrls.keySet()) {
  8. for (String url : serviceUrls.get(zone)) {
  9. try {
  10. endpoints.add(new AwsEndpoint(url, getRegion(), zone));
  11. } catch (Exception ignore) {
  12. logger.warn("Invalid eureka server URI: {}; removing from the server pool", url);
  13. }
  14. }
  15. }
  16. logger.debug("Config resolved to {}", endpoints);
  17. if (endpoints.isEmpty()) {
  18. logger.error("Cannot resolve to any endpoints from provided configuration: {}", serviceUrls);
  19. }
  20. return endpoints;
  21. }

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

  1. private URL[] enumerateJar(URL urlOfJar) {
  2. LOGGER.debug("Enumerating jar: {}", urlOfJar);
  3. List<URL> urls = new ArrayList<>();
  4. urls.add(urlOfJar);
  5. try {
  6. JarInputStream jarStream = new JarInputStream(urlOfJar.openStream());
  7. JarEntry entry;
  8. while ((entry = jarStream.getNextJarEntry()) != null) {
  9. if (!entry.isDirectory() && entry.getName().endsWith(".jar")) {
  10. urls.add(expandJarAndReturnURL(jarStream, entry));
  11. }
  12. }
  13. } catch (IOException e) {
  14. LOGGER.error("Failed to enumerate jar {}", urlOfJar, e);
  15. }
  16. return urls.toArray(new URL[0]);
  17. }

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

  1. @Override
  2. public void log (int level, String category, String message, Throwable ex) {
  3. final String logString = "[KRYO " + category + "] " + message;
  4. switch (level) {
  5. case Log.LEVEL_ERROR:
  6. log.error(logString, ex);
  7. break;
  8. case Log.LEVEL_WARN:
  9. log.warn(logString, ex);
  10. break;
  11. case Log.LEVEL_INFO:
  12. log.info(logString, ex);
  13. break;
  14. case Log.LEVEL_DEBUG:
  15. log.debug(logString, ex);
  16. break;
  17. case Log.LEVEL_TRACE:
  18. log.trace(logString, ex);
  19. break;
  20. }
  21. }
  22. }

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

  1. protected void logException() {
  2. if (exception instanceof JobNotFoundException || exception instanceof ActivitiTaskAlreadyClaimedException) {
  3. // reduce log level, because this may have been caused because of job deletion due to cancelActiviti="true"
  4. log.info("Error while closing command context",
  5. exception);
  6. } else if (exception instanceof ActivitiOptimisticLockingException) {
  7. // reduce log level, as normally we're not interested in logging this exception
  8. log.debug("Optimistic locking exception : " + exception);
  9. } else {
  10. log.error("Error while closing command context",
  11. exception);
  12. }
  13. }

代码示例来源:origin: ch.qos.logback/logback-classic

  1. public void close() {
  2. closed = true;
  3. if (serverSocket != null) {
  4. try {
  5. serverSocket.close();
  6. } catch (IOException e) {
  7. logger.error("Failed to close serverSocket", e);
  8. } finally {
  9. serverSocket = null;
  10. }
  11. }
  12. logger.info("closing this server");
  13. synchronized (socketNodeList) {
  14. for (SocketNode sn : socketNodeList) {
  15. sn.close();
  16. }
  17. }
  18. if (socketNodeList.size() != 0) {
  19. logger.warn("Was expecting a 0-sized socketNodeList after server shutdown");
  20. }
  21. }

代码示例来源:origin: skylot/jadx

  1. private static List<String> getZipFileList(File file) {
  2. List<String> filesList = new ArrayList<>();
  3. try (ZipFile zipFile = new ZipFile(file)) {
  4. Enumeration<? extends ZipEntry> entries = zipFile.entries();
  5. while (entries.hasMoreElements()) {
  6. ZipEntry entry = entries.nextElement();
  7. filesList.add(entry.getName());
  8. }
  9. } catch (Exception e) {
  10. LOG.error("Error read zip file '{}'", file.getAbsolutePath(), e);
  11. }
  12. return filesList;
  13. }

代码示例来源:origin: alibaba/fescar

  1. @Override
  2. public void onCheckMessage(long msgId, ChannelHandlerContext ctx, ServerMessageSender sender) {
  3. try {
  4. sender.sendResponse(msgId, ctx.channel(), HeartbeatMessage.PONG);
  5. } catch (Throwable throwable) {
  6. LOGGER.error("", "send response error", throwable);
  7. }
  8. if (LOGGER.isDebugEnabled()) {
  9. LOGGER.debug("received PING from " + ctx.channel().remoteAddress());
  10. }
  11. }

代码示例来源:origin: alibaba/canal

  1. futures.add(groupInnerExecutorService.submit(() -> {
  2. try {
  3. batchSync(dmls, adapter);
  4. if (logger.isDebugEnabled()) {
  5. logger.debug("{} elapsed time: {}",
  6. adapter.getClass().getName(),
  7. (System.currentTimeMillis() - begin));
  8. return true;
  9. } catch (Exception e) {
  10. logger.error(e.getMessage(), e);
  11. return false;

代码示例来源:origin: skylot/jadx

  1. public void printReport() {
  2. if (getErrorCount() > 0) {
  3. LOG.error("{} errors occurred in following nodes:", getErrorCount());
  4. List<String> errors = new ArrayList<>(errorNodes.size());
  5. for (IAttributeNode node : errorNodes) {
  6. String nodeName = node.getClass().getSimpleName().replace("Node", "");
  7. errors.add(nodeName + ": " + node);
  8. }
  9. Collections.sort(errors);
  10. for (String err : errors) {
  11. LOG.error(" {}", err);
  12. }
  13. }
  14. if (getWarnsCount() > 0) {
  15. LOG.warn("{} warnings in {} nodes", getWarnsCount(), warnNodes.size());
  16. }
  17. }
  18. }

代码示例来源:origin: alibaba/canal

  1. private void notifyStop(String destination) {
  2. InstanceAction action = actions.remove(destination);
  3. try {
  4. action.stop(destination);
  5. lastFiles.remove(destination);
  6. logger.info("auto notify stop {} successful.", destination);
  7. } catch (Throwable e) {
  8. logger.error(String.format("scan delete found[%s] but stop failed", destination), e);
  9. actions.put(destination, action);// 再重新加回去,下一次scan时再执行删除
  10. }
  11. }

代码示例来源:origin: alibaba/canal

  1. private void loadConnector(OuterAdapterConfig config, List<OuterAdapter> canalOutConnectors) {
  2. try {
  3. OuterAdapter adapter;
  4. adapter = loader.getExtension(config.getName(), StringUtils.trimToEmpty(config.getKey()));
  5. ClassLoader cl = Thread.currentThread().getContextClassLoader();
  6. // 替换ClassLoader
  7. Thread.currentThread().setContextClassLoader(adapter.getClass().getClassLoader());
  8. adapter.init(config);
  9. Thread.currentThread().setContextClassLoader(cl);
  10. canalOutConnectors.add(adapter);
  11. logger.info("Load canal adapter: {} succeed", config.getName());
  12. } catch (Exception e) {
  13. logger.error("Load canal adapter: {} failed", config.getName(), e);
  14. }
  15. }

代码示例来源:origin: alibaba/canal

  1. private void notifyReload(String destination) {
  2. InstanceAction action = actions.get(destination);
  3. if (action != null) {
  4. try {
  5. action.reload(destination);
  6. logger.info("auto notify reload {} successful.", destination);
  7. } catch (Throwable e) {
  8. logger.error(String.format("scan reload found[%s] but reload failed", destination), e);
  9. }
  10. }
  11. }

相关文章