io.vertx.core.logging.Logger.info()方法的使用及代码示例

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

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

Logger.info介绍

暂无

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Stops watching. This method stops the underlying {@link WatchService}.
 */
public void close() {
 LOGGER.info("Stopping redeployment");
 // closing the redeployment thread. If waiting, it will shutdown at the next iteration.
 closed = true;
 // Un-deploy application on close.
 undeploy.handle(null);
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Starts watching. The watch processing is made in another thread started in this method.
 *
 * @return the current watcher.
 */
public Watcher watch() {
 new Thread(this).start();
 LOGGER.info("Starting the vert.x application in redeploy mode");
 deploy.handle(null);
 return this;
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void run() throws CLIException {
 log.info(getVersion());
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Redeployment process.
 */
private void trigger() {
 long begin = System.currentTimeMillis();
 LOGGER.info("Redeploying!");
 // 1)
 undeploy.handle(v1 -> {
  // 2)
  executeUserCommand(v2 -> {
   // 3)
   deploy.handle(v3 -> {
    long end = System.currentTimeMillis();
    LOGGER.info("Redeployment done in " + (end - begin) + " ms.");
   });
  });
 });
}

代码示例来源:origin: eclipse-vertx/vert.x

private void deployHADeployments() {
 int size = toDeployOnQuorum.size();
 if (size != 0) {
  log.info("There are " + size + " HA deploymentIDs waiting on a quorum. These will now be deployed");
  Runnable task;
  while ((task = toDeployOnQuorum.poll()) != null) {
   try {
    task.run();
   } catch (Throwable t) {
    log.error("Failed to run redeployment task", t);
   }
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

private void checkQuorum() {
 if (quorumSize == 0) {
  this.attainedQuorum = true;
 } else {
  List<String> nodes = clusterManager.getNodes();
  int count = 0;
  for (String node : nodes) {
   String json = clusterMap.get(node);
   if (json != null) {
    JsonObject clusterInfo = new JsonObject(json);
    String group = clusterInfo.getString("group");
    if (group.equals(this.group)) {
     count++;
    }
   }
  }
  boolean attained = count >= quorumSize;
  if (!attainedQuorum && attained) {
   // A quorum has been attained so we can deploy any currently undeployed HA deploymentIDs
   log.info("A quorum has been obtained. Any deploymentIDs waiting on a quorum will now be deployed");
   this.attainedQuorum = true;
  } else if (attainedQuorum && !attained) {
   // We had a quorum but we lost it - we must undeploy any HA deploymentIDs
   log.info("There is no longer a quorum. Any HA deploymentIDs will be undeployed until a quorum is re-attained");
   this.attainedQuorum = false;
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Undeploys  the previously deployed verticle.
 *
 * @param completionHandler the completion handler
 */
public void undeploy(Handler<AsyncResult<Void>> completionHandler) {
 vertx.undeploy(deploymentId, res -> {
  if (res.failed()) {
   log.error("Failed in undeploying " + deploymentId, res.cause());
  } else {
   log.info("Succeeded in undeploying " + deploymentId);
  }
  deploymentId = null;
  completionHandler.handle(res);
 });
}

代码示例来源:origin: eclipse-vertx/vert.x

public void deployVerticle(final String verticleName, DeploymentOptions deploymentOptions,
              final Handler<AsyncResult<String>> doneHandler) {
 if (attainedQuorum) {
  doDeployVerticle(verticleName, deploymentOptions, doneHandler);
 } else {
  log.info("Quorum not attained. Deployment of verticle will be delayed until there's a quorum.");
  addToHADeployList(verticleName, deploymentOptions, doneHandler);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

static ResolverProvider factory(Vertx vertx, AddressResolverOptions options) {
 // For now not really plugable, we just want to not fail when we can't load the async provider
 // that use an unstable API and fallback on the default (blocking) provider
 try {
  if (!Boolean.getBoolean(DISABLE_DNS_RESOLVER_PROP_NAME)) {
   return new DnsResolverProvider((VertxImpl) vertx, options);
  }
 } catch (Throwable e) {
  if (e instanceof VertxException) {
   throw e;
  }
  Logger logger = LoggerFactory.getLogger(ResolverProvider.class);
  logger.info("Using the default address resolver as the dns resolver could not be loaded");
 }
 return new DefaultResolverProvider();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void run() {
  LoggerFactory.getLogger(getClass()).info("I'm inside anonymous class");
}

代码示例来源:origin: eclipse-vertx/vert.x

private void executeUserCommand(Handler<Void> onCompletion) {
 if (cmd != null) {
  try {
   List<String> command = new ArrayList<>();
   if (ExecUtils.isWindows()) {
    ExecUtils.addArgument(command, "cmd");
    ExecUtils.addArgument(command, "/c");
   } else {
    ExecUtils.addArgument(command, "sh");
    ExecUtils.addArgument(command, "-c");
   }
   // Do not add quote to the given command:
   command.add(cmd);
   final Process process = new ProcessBuilder(command)
     .redirectError(ProcessBuilder.Redirect.INHERIT)
     .redirectOutput(ProcessBuilder.Redirect.INHERIT)
     .start();
   int status = process.waitFor();
   LOGGER.info("User command terminated with status " + status);
  } catch (Throwable e) {
   LOGGER.error("Error while executing the on-redeploy command : '" + cmd + "'", e);
  }
 }
 onCompletion.handle(null);
}

代码示例来源:origin: eclipse-vertx/vert.x

protected void setUp() throws Exception {
 log.info("Starting test: " + this.getClass().getSimpleName() + "#" + name.getMethodName());
 mainThreadName = Thread.currentThread().getName();
 tearingDown = false;
 waitFor(1);
 throwable = null;
 testCompleteCalled = false;
 awaitCalled = false;
 threadNames.clear();
 lateFailure = false;
}

代码示例来源:origin: eclipse-vertx/vert.x

private Handler<AsyncResult<String>> createHandler(final String message,
                          final Handler<AsyncResult<String>>
                            completionHandler) {
  return res -> {
   if (res.failed()) {
    Throwable cause = res.cause();
    cause.printStackTrace();
    if (cause instanceof VertxException) {
     VertxException ve = (VertxException) cause;
     log.error(ve.getMessage());
     if (ve.getCause() != null) {
      log.error(ve.getCause());
     }
    } else {
     log.error("Failed in " + message, cause);
    }
   } else {
    deploymentId = res.result();
    log.info("Succeeded in " + message);
   }
   if (completionHandler != null) {
    completionHandler.handle(res);
   }
  };
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

private <T> Handler<AsyncResult<T>> createLoggingHandler(final String message, final Handler<AsyncResult<T>> completionHandler) {
 return res -> {
  if (res.failed()) {
   Throwable cause = res.cause();
   if (cause instanceof VertxException) {
    VertxException ve = (VertxException)cause;
    log.error(ve.getMessage());
    if (ve.getCause() != null) {
     log.error(ve.getCause());
    }
   } else {
    log.error("Failed in " + message, cause);
   }
  } else {
   log.info("Succeeded in " + message);
  }
  if (completionHandler != null) {
   completionHandler.handle(res);
  }
 };
}

代码示例来源:origin: eclipse-vertx/vert.x

public void run(Args args, String[] sargs) {
 PROCESS_ARGS = Collections.unmodifiableList(Arrays.asList(sargs));
 String main = readMainVerticleFromManifest();
 if (main != null) {
  runVerticle(main, args);
 } else {
  if (sargs.length > 0) {
   String first = sargs[0];
   if (first.equals("-version")) {
    log.info(getVersion());
    return;
   } else if (first.equals("run")) {
    if (sargs.length < 2) {
     displaySyntax();
     return;
    } else {
     main = sargs[1];
     runVerticle(main, args);
     return;
    }
   } else if (first.equals("-ha")) {
    // Create a bare instance
    runBare(args);
    return;
   }
  }
  displaySyntax();
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Creates a new {@link Watcher}.
 *
 * @param root              the root directory
 * @param includes          the list of include patterns, should not be {@code null} or empty
 * @param deploy            the function called when deployment is required
 * @param undeploy          the function called when un-deployment is required
 * @param onRedeployCommand an optional command executed after the un-deployment and before the deployment
 * @param gracePeriod       the amount of time in milliseconds to wait between two redeploy even
 *                          if there are changes
 * @param scanPeriod        the time in millisecond between 2 file system scans
 */
public Watcher(File root, List<String> includes, Handler<Handler<Void>> deploy, Handler<Handler<Void>> undeploy,
        String onRedeployCommand, long gracePeriod, long scanPeriod) {
 this.gracePeriod = gracePeriod;
 this.includes = sanitizeIncludePatterns(includes);
 this.roots = extractRoots(root, this.includes);
 this.cwd = root;
 LOGGER.info("Watched paths: " + this.roots);
 this.deploy = deploy;
 this.undeploy = undeploy;
 this.cmd = onRedeployCommand;
 this.scanPeriod = scanPeriod;
 addFilesToWatchedList(roots);
}

代码示例来源:origin: eclipse-vertx/vert.x

private void checkFailover(String failedNodeID, JsonObject theHAInfo) {
 try {
  JsonArray deployments = theHAInfo.getJsonArray("verticles");
  String group = theHAInfo.getString("group");
  String chosen = chooseHashedNode(group, failedNodeID.hashCode());
  if (chosen != null && chosen.equals(this.nodeID)) {
   if (deployments != null && deployments.size() != 0) {
    log.info("node" + nodeID + " says: Node " + failedNodeID + " has failed. This node will deploy " + deployments.size() + " deploymentIDs from that node.");
    for (Object obj: deployments) {
     JsonObject app = (JsonObject)obj;
     processFailover(app);
    }
   }
   // Failover is complete! We can now remove the failed node from the cluster map
   clusterMap.remove(failedNodeID);
   runOnContextAndWait(() -> {
    if (failoverCompleteHandler != null) {
     failoverCompleteHandler.handle(failedNodeID, theHAInfo, true);
    }
   });
  }
 } catch (Throwable t) {
  log.error("Failed to handle failover", t);
  runOnContextAndWait(() -> {
   if (failoverCompleteHandler != null) {
    failoverCompleteHandler.handle(failedNodeID, theHAInfo, false);
   }
  });
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

private void testInfo(Logger logger) {
 String result = record(() -> logger.info("hello"));
 assertContains("[main] INFO my-slf4j-logger - hello", result);
 result = record(() -> logger.info("exception", new NullPointerException()));
 assertTrue(result.contains("[main] INFO my-slf4j-logger - exception"));
 assertTrue(result.contains("java.lang.NullPointerException"));
 result = record(() -> logger.info("hello {} and {}", "Paulo", "Julien"));
 assertContains("[main] INFO my-slf4j-logger - hello Paulo and Julien", result);
 result = record(() -> logger.info("hello {}", "vert.x"));
 assertContains("[main] INFO my-slf4j-logger - hello vert.x", result);
 result = record(() -> logger.info("hello {} - {}", "vert.x"));
 assertContains("[main] INFO my-slf4j-logger - hello vert.x - {}", result);
 result = record(() -> logger.info("hello {}", "vert.x", "foo"));
 assertContains("[main] INFO my-slf4j-logger - hello vert.x", result);
 result = record(() -> logger.info("{}, an exception has been thrown", new IllegalStateException(), "Luke"));
 assertTrue(result.contains("[main] INFO my-slf4j-logger - Luke, an exception has been thrown"));
 assertTrue(result.contains("java.lang.IllegalStateException"));
 result = record(() -> logger.info("{}, an exception has been thrown", "Luke", new IllegalStateException()));
 assertTrue(result.contains("[main] INFO my-slf4j-logger - Luke, an exception has been thrown"));
 assertTrue(result.contains("java.lang.IllegalStateException"));
}

代码示例来源:origin: eclipse-vertx/vert.x

private void undeployHADeployments() {
 for (String deploymentID: deploymentManager.deployments()) {
  Deployment dep = deploymentManager.getDeployment(deploymentID);
  if (dep != null) {
   if (dep.deploymentOptions().isHa()) {
    ContextInternal ctx = vertx.getContext();
    try {
     ContextImpl.setContext(null);
     deploymentManager.undeployVerticle(deploymentID, result -> {
      if (result.succeeded()) {
       log.info("Successfully undeployed HA deployment " + deploymentID + "-" + dep.verticleIdentifier() + " as there is no quorum");
       addToHADeployList(dep.verticleIdentifier(), dep.deploymentOptions(), result1 -> {
        if (result1.succeeded()) {
         log.info("Successfully redeployed verticle " + dep.verticleIdentifier() + " after quorum was re-attained");
        } else {
         log.error("Failed to redeploy verticle " + dep.verticleIdentifier() + " after quorum was re-attained", result1.cause());
        }
       });
      } else {
       log.error("Failed to undeploy deployment on lost quorum", result.cause());
      }
     });
    } finally {
     ContextImpl.setContext((ContextImpl) ctx);
    }
   }
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

Logger logger = LoggerFactory.getLogger("my-log4j2-logger");
String result = recording.execute(() -> {
 logger.info("hello");
});
assertTrue(result.contains("hello"));
result = recording.execute(() -> {
 logger.info("exception", new NullPointerException());
});
assertTrue(result.contains("exception"));
 logger.info("hello {} and {}", "Paulo", "Julien");
});
assertTrue(result.contains("hello Paulo and Julien"));
 logger.info("hello {}", "vert.x");
});
String expected = "hello vert.x";
 logger.info("hello {} - {}", "vert.x");
});
assertTrue(result.contains("hello vert.x - {}"));
 logger.info("hello {} {}", "vert.x", "foo");
});
assertTrue(result.contains("hello vert.x foo"));
 logger.info("{}, an exception has been thrown", new IllegalStateException(), "Luke");
});
assertTrue(result.contains("Luke, an exception has been thrown"));

相关文章