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

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

本文整理了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

  1. @SuppressWarnings({ "unchecked", "rawtypes" })
  2. @Override
  3. public Set<? extends Image> get() {
  4. if (amiOwners.length == 0) {
  5. logger.debug(">> no owners specified, skipping image parsing");
  6. return ImmutableSet.of();
  7. } else {
  8. logger.debug(">> providing images");
  9. Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions.get(),
  10. amiOwners);
  11. Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates
  12. .notNull()));
  13. Map<RegionAndName, ? extends Image> imageMap = ImagesToRegionAndIdMap.imagesToMap(parsedImages);
  14. cache.get().invalidateAll();
  15. cache.get().asMap().putAll((Map)imageMap);
  16. logger.debug("<< images(%d)", imageMap.size());
  17. return Sets.newLinkedHashSet(imageMap.values());
  18. }
  19. }

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public ListenableFuture<DriveInfo> apply(String input) {
  3. try {
  4. return Futures.immediateFuture(cache.getUnchecked(input));
  5. } catch (CacheLoader.InvalidCacheLoadException e) {
  6. logger.debug("drive %s not found", input);
  7. } catch (UncheckedExecutionException e) {
  8. logger.warn(e, "error finding drive %s: %s", input, e.getMessage());
  9. }
  10. return Futures.immediateFuture(null);
  11. }

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

  1. @Override
  2. public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) {
  3. if (checkNotNull(regionAndIds, "regionAndIds").isEmpty())
  4. return ImmutableSet.of();
  5. Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder();
  6. Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()),
  7. nameFunction());
  8. for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) {
  9. String region = entry.getKey();
  10. Collection<String> instanceIds = entry.getValue();
  11. logger.trace("looking for instances %s in region %s", instanceIds, region);
  12. builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region,
  13. toArray(instanceIds, String.class))));
  14. }
  15. return builder.build();
  16. }

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

  1. private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
  2. Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId);
  3. if (securityGroupApi.isPresent()) {
  4. for (String group : groups) {
  5. for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(),
  6. SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) {
  7. ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName());
  8. logger.debug(">> deleting securityGroup(%s)", zoneAndName);
  9. securityGroupApi.get().delete(securityGroup.getId());
  10. // TODO: test this clear happens
  11. securityGroupMap.invalidate(zoneAndName);
  12. logger.debug("<< deleted securityGroup(%s)", zoneAndName);
  13. }
  14. }
  15. }
  16. }

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

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

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

  1. protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count,
  2. Template template, RunInstancesOptions instanceOptions) {
  3. int countStarted = 0;
  4. int tries = 0;
  5. Set<RunningInstance> started = ImmutableSet.<RunningInstance> of();
  6. while (countStarted < count && tries++ < count) {
  7. if (logger.isDebugEnabled())
  8. logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region,
  9. zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters());
  10. started = ImmutableSet.copyOf(concat(
  11. started,
  12. client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1,
  13. count - countStarted, instanceOptions)));
  14. countStarted = size(started);
  15. if (countStarted < count)
  16. logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count);
  17. }
  18. return started;
  19. }

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

  1. @Singleton
  2. @Zone
  3. @Override
  4. public Map<String, Supplier<Set<String>>> get() {
  5. Set<String> regions = regionsSupplier.get();
  6. if (regions.size() == 0) {
  7. logger.debug("no regions configured for provider %s", provider);
  8. return ImmutableMap.of();
  9. }
  10. Builder<String, Supplier<Set<String>>> regionToZones = ImmutableMap.builder();
  11. for (String region : regions) {
  12. String configKey = PROPERTY_REGION + "." + region + ".zones";
  13. String zones = config.apply(configKey);
  14. if (zones == null)
  15. logger.debug("config key %s not present", configKey);
  16. else
  17. regionToZones.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',').split(
  18. zones))));
  19. }
  20. return regionToZones.build();
  21. }
  22. }

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

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

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

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

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

  1. public ExecResponse runAction(String action) {
  2. ExecResponse returnVal;
  3. String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action)
  4. : execScriptAsDefaultUser(action);
  5. returnVal = runCommand(command);
  6. if (ImmutableSet.of("status", "stdout", "stderr").contains(action))
  7. logger.trace("<< %s(%d)", action, returnVal.getExitStatus());
  8. else if (computeLogger.isTraceEnabled())
  9. computeLogger.trace("<< %s[%s]", action, returnVal);
  10. else
  11. computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus());
  12. return returnVal;
  13. }

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

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

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

  1. private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
  2. Zone zone = zoneIdToZone.get().getUnchecked(zoneId);
  3. if (supportsSecurityGroups().apply(zone)) {
  4. for (String group : groups) {
  5. for (SecurityGroup securityGroup : Iterables.filter(client.getSecurityGroupApi().listSecurityGroups(),
  6. SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) {
  7. ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName());
  8. logger.debug(">> deleting securityGroup(%s)", zoneAndName);
  9. client.getSecurityGroupApi().deleteSecurityGroup(securityGroup.getId());
  10. // TODO: test this clear happens
  11. securityGroupMap.invalidate(zoneAndName);
  12. logger.debug("<< deleted securityGroup(%s)", zoneAndName);
  13. }
  14. }
  15. }
  16. }

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

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

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

  1. @Override
  2. public ZoneAndId apply(ZoneAndId id) {
  3. FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get();
  4. for (FloatingIP ip : floatingIpCache.getUnchecked(id)) {
  5. logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id);
  6. floatingIpApi.removeFromServer(ip.getIp(), id.getId());
  7. logger.debug(">> deallocating floatingIp(%s)", ip);
  8. floatingIpApi.delete(ip.getId());
  9. }
  10. floatingIpCache.invalidate(id);
  11. return id;
  12. }

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

  1. @Override
  2. public Map<String, Supplier<URI>> get() {
  3. FluentIterable<Service> services = FluentIterable.from(access.get()).filter(apiTypeEquals);
  4. if (services.toSet().size() == 0)
  5. throw new NoSuchElementException(String.format("apiType %s not found in catalog %s", apiType, services));
  6. Iterable<Endpoint> endpoints = concat(services);
  7. if (size(endpoints) == 0)
  8. throw new NoSuchElementException(
  9. String.format("no endpoints for apiType %s in services %s", apiType, services));
  10. boolean checkVersionId = any(endpoints, versionAware);
  11. Multimap<String, Endpoint> locationToEndpoints = index(endpoints, endpointToLocationId);
  12. Map<String, Endpoint> locationToEndpoint;
  13. if (checkVersionId && apiVersion != null) {
  14. locationToEndpoint = refineToVersionSpecificEndpoint(locationToEndpoints);
  15. if (locationToEndpoint.size() == 0)
  16. throw new NoSuchElementException(String.format(
  17. "no endpoints for apiType %s are of version %s, or version agnostic: %s", apiType, apiVersion,
  18. locationToEndpoints));
  19. } else {
  20. locationToEndpoint = firstEndpointInLocation(locationToEndpoints);
  21. }
  22. logger.debug("endpoints for apiType %s and version %s: %s", apiType, apiVersion, locationToEndpoints);
  23. return Maps.transformValues(locationToEndpoint, endpointToSupplierURI);
  24. }

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

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

相关文章