org.jclouds.logging.Logger类的使用及代码示例

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

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

Logger介绍

[英]JClouds log abstraction layer.

Implementations of logging are optional and injected if they are configured.

@Resource Logger logger = Logger.NULL; The above will get you a null-safe instance of Logger. If configured, this logger will be swapped with a real Logger implementation with category set to the current class name. This is done post-object construction, so do not attempt to use these loggers in your constructor.

If you wish to initialize loggers like these yourself, do not use the @Resource annotation.

This implementation first checks to see if the level is enabled before issuing the log command. In other words, don't do the following if (logger.isTraceEnabled()) logger.trace("message");.

[中]JClouds日志抽象层。 日志记录的实现是可选的,如果配置了日志记录,则可以进行注入。 `@Resource Logger logger = Logger.NULL;`以上内容将为您提供一个空安全的Logger实例。如果配置,此记录器将与类别设置为当前类名的真实记录器实现交换。这是在对象构造之后完成的,所以不要试图在构造函数中使用这些记录器。 如果您希望自己初始化这些记录器,请不要使用@Resource注释。 在发出log命令之前,此实现首先检查该级别是否已启用。换句话说,不要执行以下操作`if (logger.isTraceEnabled()) logger.trace("message");. `

代码示例

代码示例来源:origin: jclouds/legacy-jclouds

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Set<? extends Image> get() {
 if (amiOwners.length == 0) {
   logger.debug(">> no owners specified, skipping image parsing");
   return ImmutableSet.of();
 
 } else {
   logger.debug(">> providing images");
   Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions.get(),
       amiOwners);
   Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates
       .notNull()));
   Map<RegionAndName, ? extends Image> imageMap = ImagesToRegionAndIdMap.imagesToMap(parsedImages);
   cache.get().invalidateAll();
   cache.get().asMap().putAll((Map)imageMap);
   logger.debug("<< images(%d)", imageMap.size());
      return Sets.newLinkedHashSet(imageMap.values());
 }
}

代码示例来源:origin: com.amysta.jclouds.api/elasticstack

private OsFamily extractOsFamily(final String name) {
 final String lowerCaseName = name.toLowerCase();
 Optional<OsFamily> family = tryFind(asList(OsFamily.values()), new Predicate<OsFamily>() {
   @Override
   public boolean apply(OsFamily input) {
    return lowerCaseName.startsWith(input.name().toLowerCase());
   }
 });
 if (!family.isPresent()) {
   logger.warn("could not find the operating system family for image: %s", name);
 }
 return family.or(OsFamily.UNRECOGNIZED);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public InputStream apply(URI input) {
 try {
   if (input.getScheme() != null && input.getScheme().equals("classpath"))
    return getClass().getResourceAsStream(input.getPath());
   return input.toURL().openStream();
 } catch (IOException e) {
   logger.error(e, "URI could not be read: %s", url);
   throw Throwables.propagate(e);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingHardwareIds(String message, Iterable<? extends Hardware> hardwares) {
 NoSuchElementException exception = new NoSuchElementException(message);
 if (logger.isTraceEnabled())
   logger.warn(exception, "hardware ids that didn't match: %s", transform(hardwares, hardwareToId));
 throw exception;
}

代码示例来源:origin: jclouds/legacy-jclouds

public void awaitCompletion(Iterable<String> jobs) {
 logger.debug(">> awaiting completion of jobs(%s)", jobs);
 for (String job : jobs)
   awaitCompletion(job);
 logger.trace("<< completed jobs(%s)", jobs);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public ListenableFuture<DriveInfo> apply(String input) {
 try {
   return Futures.immediateFuture(cache.getUnchecked(input));
 } catch (CacheLoader.InvalidCacheLoadException e) {
   logger.debug("drive %s not found", input);
 } catch (UncheckedExecutionException e) {
   logger.warn(e, "error finding drive %s: %s", input, e.getMessage());
 }
 return Futures.immediateFuture(null);
}

代码示例来源:origin: org.apache.jclouds.api/ec2

@Override
public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) {
 if (checkNotNull(regionAndIds, "regionAndIds").isEmpty())
   return ImmutableSet.of();
 Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder();
 Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()),
    nameFunction());
 for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) {
   String region = entry.getKey();
   Collection<String> instanceIds = entry.getValue();
   logger.trace("looking for instances %s in region %s", instanceIds, region);
   builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region,
      toArray(instanceIds, String.class))));
 }
 return builder.build();
}

代码示例来源:origin: jclouds/legacy-jclouds

private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
 Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId);
 if (securityGroupApi.isPresent()) {
   for (String group : groups) {
    for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(),
         SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) {
      ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName());
      logger.debug(">> deleting securityGroup(%s)", zoneAndName);
      securityGroupApi.get().delete(securityGroup.getId());
      // TODO: test this clear happens
      securityGroupMap.invalidate(zoneAndName);
      logger.debug("<< deleted securityGroup(%s)", zoneAndName);
    }
   }
 }
}

代码示例来源:origin: io.cloudsoft.jclouds.provider/aws-ec2

protected Set<RunningInstance> getSpots(Set<RegionAndName> regionAndIds) {
 Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder();
 Multimap<String, String> regionToSpotIds = transformValues(index(regionAndIds, regionFunction()), nameFunction());
 for (Map.Entry<String, Collection<String>> entry : regionToSpotIds.asMap().entrySet()) {
   String region = entry.getKey();
   Collection<String> spotIds = entry.getValue();
   logger.trace("looking for spots %s in region %s", spotIds, region);
   builder.addAll(transform(
               client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(region,
         toArray(spotIds, String.class)), spotConverter));
 }
 return builder.build();
}

代码示例来源:origin: jclouds/legacy-jclouds

protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count,
   Template template, RunInstancesOptions instanceOptions) {
 int countStarted = 0;
 int tries = 0;
 Set<RunningInstance> started = ImmutableSet.<RunningInstance> of();
 while (countStarted < count && tries++ < count) {
   if (logger.isDebugEnabled())
    logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region,
       zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters());
   started = ImmutableSet.copyOf(concat(
      started,
      client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1,
         count - countStarted, instanceOptions)));
   countStarted = size(started);
   if (countStarted < count)
    logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count);
 }
 return started;
}

代码示例来源:origin: org.jclouds/jclouds-core

@Singleton
  @Zone
  @Override
  public Map<String, Supplier<Set<String>>> get() {
   Set<String> regions = regionsSupplier.get();
   if (regions.size() == 0) {
     logger.debug("no regions configured for provider %s", provider);
     return ImmutableMap.of();
   }
   Builder<String, Supplier<Set<String>>> regionToZones = ImmutableMap.builder();
   for (String region : regions) {
     String configKey = PROPERTY_REGION + "." + region + ".zones";
     String zones = config.apply(configKey);
     if (zones == null)
      logger.debug("config key %s not present", configKey);
     else
      regionToZones.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',').split(
           zones))));
   }
   return regionToZones.build();

  }
}

代码示例来源:origin: org.jclouds/jclouds-core

@Override
public Set<String> get() {
 String regionString = config.apply(configKey);
 if (regionString == null) {
   logger.debug("no %s configured for provider %s", configKey, provider);
   return ImmutableSet.of();
 } else {
   return ImmutableSet.copyOf(Splitter.on(',').split(regionString));
 }
}

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

@Test(groups = { "integration", "live" }, singleThreaded = true)
public void testListSecurityGroupsForNode() throws RunNodesException, InterruptedException, ExecutionException {
 skipIfSecurityGroupsNotSupported();
 ComputeService computeService = view.getComputeService();
 Optional<SecurityGroupExtension> securityGroupExtension = computeService.getSecurityGroupExtension();
 assertTrue(securityGroupExtension.isPresent(), "security extension was not present");
 for (SecurityGroup securityGroup : securityGroupExtension.get().listSecurityGroupsForNode("uk-1/97374b9f-c706-4c4a-ae5a-48b6d2e58db9")) {
   logger.info(securityGroup.toString());
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public ExecResponse runAction(String action) {
 ExecResponse returnVal;
 String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action)
    : execScriptAsDefaultUser(action);
 returnVal = runCommand(command);
 if (ImmutableSet.of("status", "stdout", "stderr").contains(action))
   logger.trace("<< %s(%d)", action, returnVal.getExitStatus());
 else if (computeLogger.isTraceEnabled())
   computeLogger.trace("<< %s[%s]", action, returnVal);
 else
   computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus());
 return returnVal;
}

代码示例来源:origin: jclouds/legacy-jclouds

/**
* Prioritizes endpoint.versionId over endpoint.id when matching
*/
private Optional<Endpoint> strictMatchEndpointVersion(Iterable<Endpoint> endpoints, String locationId) {
 Optional<Endpoint> endpointOfVersion = tryFind(endpoints, apiVersionEqualsVersionId);
 if (!endpointOfVersion.isPresent())
   logger.debug("no endpoints of apiType %s matched expected version %s in location %s: %s", apiType, apiVersion,
      locationId, endpoints);
 return endpointOfVersion;
}

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

private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
 Zone zone = zoneIdToZone.get().getUnchecked(zoneId);
 if (supportsSecurityGroups().apply(zone)) {
   for (String group : groups) {
    for (SecurityGroup securityGroup : Iterables.filter(client.getSecurityGroupApi().listSecurityGroups(),
         SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) {
      ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName());
      logger.debug(">> deleting securityGroup(%s)", zoneAndName);
      client.getSecurityGroupApi().deleteSecurityGroup(securityGroup.getId());
      // TODO: test this clear happens
      securityGroupMap.invalidate(zoneAndName);
      logger.debug("<< deleted securityGroup(%s)", zoneAndName);
    }
   }
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

/**
  * Terremark does not provide vApp templates in the vDC resourceEntity list. Rather, you must
  * query the catalog.
  */
  @Override
  public Set<? extends Image> get() {
   logger.debug(">> providing vAppTemplates");
   return newLinkedHashSet(concat(transform(organizationsForLocations.apply(locations.get()), imagesInOrg)));
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public ZoneAndId apply(ZoneAndId id) {
 FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get();
 for (FloatingIP ip : floatingIpCache.getUnchecked(id)) {
   logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id);
   floatingIpApi.removeFromServer(ip.getIp(), id.getId());
   logger.debug(">> deallocating floatingIp(%s)", ip);
   floatingIpApi.delete(ip.getId());
 }
 floatingIpCache.invalidate(id);
 return id;
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public Map<String, Supplier<URI>> get() {
 FluentIterable<Service> services = FluentIterable.from(access.get()).filter(apiTypeEquals);
 if (services.toSet().size() == 0)
   throw new NoSuchElementException(String.format("apiType %s not found in catalog %s", apiType, services));
 Iterable<Endpoint> endpoints = concat(services);
 if (size(endpoints) == 0)
   throw new NoSuchElementException(
      String.format("no endpoints for apiType %s in services %s", apiType, services));
 boolean checkVersionId = any(endpoints, versionAware);
 Multimap<String, Endpoint> locationToEndpoints = index(endpoints, endpointToLocationId);
 Map<String, Endpoint> locationToEndpoint;
 if (checkVersionId && apiVersion != null) {
   locationToEndpoint = refineToVersionSpecificEndpoint(locationToEndpoints);
   if (locationToEndpoint.size() == 0)
    throw new NoSuchElementException(String.format(
       "no endpoints for apiType %s are of version %s, or version agnostic: %s", apiType, apiVersion,
       locationToEndpoints));
 } else {
   locationToEndpoint = firstEndpointInLocation(locationToEndpoints);
 }
 logger.debug("endpoints for apiType %s and version %s: %s", apiType, apiVersion, locationToEndpoints);
 return Maps.transformValues(locationToEndpoint, endpointToSupplierURI);
}

代码示例来源:origin: jclouds/legacy-jclouds

protected Hardware parseHardware(Server from) {
 try {
   return Iterables.find(hardwares.get(), new FindHardwareForServer(from));
 } catch (NoSuchElementException e) {
   logger.debug("could not find a matching hardware for server %s", from);
 }
 return null;
}

相关文章