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

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

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

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

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

  1. /**
  2. * Starts watching. The watch processing is made in another thread started in this method.
  3. *
  4. * @return the current watcher.
  5. */
  6. public Watcher watch() {
  7. new Thread(this).start();
  8. LOGGER.info("Starting the vert.x application in redeploy mode");
  9. deploy.handle(null);
  10. return this;
  11. }

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

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

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

  1. /**
  2. * Redeployment process.
  3. */
  4. private void trigger() {
  5. long begin = System.currentTimeMillis();
  6. LOGGER.info("Redeploying!");
  7. // 1)
  8. undeploy.handle(v1 -> {
  9. // 2)
  10. executeUserCommand(v2 -> {
  11. // 3)
  12. deploy.handle(v3 -> {
  13. long end = System.currentTimeMillis();
  14. LOGGER.info("Redeployment done in " + (end - begin) + " ms.");
  15. });
  16. });
  17. });
  18. }

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

  1. private void deployHADeployments() {
  2. int size = toDeployOnQuorum.size();
  3. if (size != 0) {
  4. log.info("There are " + size + " HA deploymentIDs waiting on a quorum. These will now be deployed");
  5. Runnable task;
  6. while ((task = toDeployOnQuorum.poll()) != null) {
  7. try {
  8. task.run();
  9. } catch (Throwable t) {
  10. log.error("Failed to run redeployment task", t);
  11. }
  12. }
  13. }
  14. }

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

  1. private void checkQuorum() {
  2. if (quorumSize == 0) {
  3. this.attainedQuorum = true;
  4. } else {
  5. List<String> nodes = clusterManager.getNodes();
  6. int count = 0;
  7. for (String node : nodes) {
  8. String json = clusterMap.get(node);
  9. if (json != null) {
  10. JsonObject clusterInfo = new JsonObject(json);
  11. String group = clusterInfo.getString("group");
  12. if (group.equals(this.group)) {
  13. count++;
  14. }
  15. }
  16. }
  17. boolean attained = count >= quorumSize;
  18. if (!attainedQuorum && attained) {
  19. // A quorum has been attained so we can deploy any currently undeployed HA deploymentIDs
  20. log.info("A quorum has been obtained. Any deploymentIDs waiting on a quorum will now be deployed");
  21. this.attainedQuorum = true;
  22. } else if (attainedQuorum && !attained) {
  23. // We had a quorum but we lost it - we must undeploy any HA deploymentIDs
  24. log.info("There is no longer a quorum. Any HA deploymentIDs will be undeployed until a quorum is re-attained");
  25. this.attainedQuorum = false;
  26. }
  27. }
  28. }

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

  1. /**
  2. * Undeploys the previously deployed verticle.
  3. *
  4. * @param completionHandler the completion handler
  5. */
  6. public void undeploy(Handler<AsyncResult<Void>> completionHandler) {
  7. vertx.undeploy(deploymentId, res -> {
  8. if (res.failed()) {
  9. log.error("Failed in undeploying " + deploymentId, res.cause());
  10. } else {
  11. log.info("Succeeded in undeploying " + deploymentId);
  12. }
  13. deploymentId = null;
  14. completionHandler.handle(res);
  15. });
  16. }

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

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

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

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

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

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

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

  1. private void executeUserCommand(Handler<Void> onCompletion) {
  2. if (cmd != null) {
  3. try {
  4. List<String> command = new ArrayList<>();
  5. if (ExecUtils.isWindows()) {
  6. ExecUtils.addArgument(command, "cmd");
  7. ExecUtils.addArgument(command, "/c");
  8. } else {
  9. ExecUtils.addArgument(command, "sh");
  10. ExecUtils.addArgument(command, "-c");
  11. }
  12. // Do not add quote to the given command:
  13. command.add(cmd);
  14. final Process process = new ProcessBuilder(command)
  15. .redirectError(ProcessBuilder.Redirect.INHERIT)
  16. .redirectOutput(ProcessBuilder.Redirect.INHERIT)
  17. .start();
  18. int status = process.waitFor();
  19. LOGGER.info("User command terminated with status " + status);
  20. } catch (Throwable e) {
  21. LOGGER.error("Error while executing the on-redeploy command : '" + cmd + "'", e);
  22. }
  23. }
  24. onCompletion.handle(null);
  25. }

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

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

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

  1. private Handler<AsyncResult<String>> createHandler(final String message,
  2. final Handler<AsyncResult<String>>
  3. completionHandler) {
  4. return res -> {
  5. if (res.failed()) {
  6. Throwable cause = res.cause();
  7. cause.printStackTrace();
  8. if (cause instanceof VertxException) {
  9. VertxException ve = (VertxException) cause;
  10. log.error(ve.getMessage());
  11. if (ve.getCause() != null) {
  12. log.error(ve.getCause());
  13. }
  14. } else {
  15. log.error("Failed in " + message, cause);
  16. }
  17. } else {
  18. deploymentId = res.result();
  19. log.info("Succeeded in " + message);
  20. }
  21. if (completionHandler != null) {
  22. completionHandler.handle(res);
  23. }
  24. };
  25. }
  26. }

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

  1. private <T> Handler<AsyncResult<T>> createLoggingHandler(final String message, final Handler<AsyncResult<T>> completionHandler) {
  2. return res -> {
  3. if (res.failed()) {
  4. Throwable cause = res.cause();
  5. if (cause instanceof VertxException) {
  6. VertxException ve = (VertxException)cause;
  7. log.error(ve.getMessage());
  8. if (ve.getCause() != null) {
  9. log.error(ve.getCause());
  10. }
  11. } else {
  12. log.error("Failed in " + message, cause);
  13. }
  14. } else {
  15. log.info("Succeeded in " + message);
  16. }
  17. if (completionHandler != null) {
  18. completionHandler.handle(res);
  19. }
  20. };
  21. }

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

  1. public void run(Args args, String[] sargs) {
  2. PROCESS_ARGS = Collections.unmodifiableList(Arrays.asList(sargs));
  3. String main = readMainVerticleFromManifest();
  4. if (main != null) {
  5. runVerticle(main, args);
  6. } else {
  7. if (sargs.length > 0) {
  8. String first = sargs[0];
  9. if (first.equals("-version")) {
  10. log.info(getVersion());
  11. return;
  12. } else if (first.equals("run")) {
  13. if (sargs.length < 2) {
  14. displaySyntax();
  15. return;
  16. } else {
  17. main = sargs[1];
  18. runVerticle(main, args);
  19. return;
  20. }
  21. } else if (first.equals("-ha")) {
  22. // Create a bare instance
  23. runBare(args);
  24. return;
  25. }
  26. }
  27. displaySyntax();
  28. }
  29. }

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

  1. /**
  2. * Creates a new {@link Watcher}.
  3. *
  4. * @param root the root directory
  5. * @param includes the list of include patterns, should not be {@code null} or empty
  6. * @param deploy the function called when deployment is required
  7. * @param undeploy the function called when un-deployment is required
  8. * @param onRedeployCommand an optional command executed after the un-deployment and before the deployment
  9. * @param gracePeriod the amount of time in milliseconds to wait between two redeploy even
  10. * if there are changes
  11. * @param scanPeriod the time in millisecond between 2 file system scans
  12. */
  13. public Watcher(File root, List<String> includes, Handler<Handler<Void>> deploy, Handler<Handler<Void>> undeploy,
  14. String onRedeployCommand, long gracePeriod, long scanPeriod) {
  15. this.gracePeriod = gracePeriod;
  16. this.includes = sanitizeIncludePatterns(includes);
  17. this.roots = extractRoots(root, this.includes);
  18. this.cwd = root;
  19. LOGGER.info("Watched paths: " + this.roots);
  20. this.deploy = deploy;
  21. this.undeploy = undeploy;
  22. this.cmd = onRedeployCommand;
  23. this.scanPeriod = scanPeriod;
  24. addFilesToWatchedList(roots);
  25. }

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

  1. private void checkFailover(String failedNodeID, JsonObject theHAInfo) {
  2. try {
  3. JsonArray deployments = theHAInfo.getJsonArray("verticles");
  4. String group = theHAInfo.getString("group");
  5. String chosen = chooseHashedNode(group, failedNodeID.hashCode());
  6. if (chosen != null && chosen.equals(this.nodeID)) {
  7. if (deployments != null && deployments.size() != 0) {
  8. log.info("node" + nodeID + " says: Node " + failedNodeID + " has failed. This node will deploy " + deployments.size() + " deploymentIDs from that node.");
  9. for (Object obj: deployments) {
  10. JsonObject app = (JsonObject)obj;
  11. processFailover(app);
  12. }
  13. }
  14. // Failover is complete! We can now remove the failed node from the cluster map
  15. clusterMap.remove(failedNodeID);
  16. runOnContextAndWait(() -> {
  17. if (failoverCompleteHandler != null) {
  18. failoverCompleteHandler.handle(failedNodeID, theHAInfo, true);
  19. }
  20. });
  21. }
  22. } catch (Throwable t) {
  23. log.error("Failed to handle failover", t);
  24. runOnContextAndWait(() -> {
  25. if (failoverCompleteHandler != null) {
  26. failoverCompleteHandler.handle(failedNodeID, theHAInfo, false);
  27. }
  28. });
  29. }
  30. }

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

  1. private void testInfo(Logger logger) {
  2. String result = record(() -> logger.info("hello"));
  3. assertContains("[main] INFO my-slf4j-logger - hello", result);
  4. result = record(() -> logger.info("exception", new NullPointerException()));
  5. assertTrue(result.contains("[main] INFO my-slf4j-logger - exception"));
  6. assertTrue(result.contains("java.lang.NullPointerException"));
  7. result = record(() -> logger.info("hello {} and {}", "Paulo", "Julien"));
  8. assertContains("[main] INFO my-slf4j-logger - hello Paulo and Julien", result);
  9. result = record(() -> logger.info("hello {}", "vert.x"));
  10. assertContains("[main] INFO my-slf4j-logger - hello vert.x", result);
  11. result = record(() -> logger.info("hello {} - {}", "vert.x"));
  12. assertContains("[main] INFO my-slf4j-logger - hello vert.x - {}", result);
  13. result = record(() -> logger.info("hello {}", "vert.x", "foo"));
  14. assertContains("[main] INFO my-slf4j-logger - hello vert.x", result);
  15. result = record(() -> logger.info("{}, an exception has been thrown", new IllegalStateException(), "Luke"));
  16. assertTrue(result.contains("[main] INFO my-slf4j-logger - Luke, an exception has been thrown"));
  17. assertTrue(result.contains("java.lang.IllegalStateException"));
  18. result = record(() -> logger.info("{}, an exception has been thrown", "Luke", new IllegalStateException()));
  19. assertTrue(result.contains("[main] INFO my-slf4j-logger - Luke, an exception has been thrown"));
  20. assertTrue(result.contains("java.lang.IllegalStateException"));
  21. }

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

  1. private void undeployHADeployments() {
  2. for (String deploymentID: deploymentManager.deployments()) {
  3. Deployment dep = deploymentManager.getDeployment(deploymentID);
  4. if (dep != null) {
  5. if (dep.deploymentOptions().isHa()) {
  6. ContextInternal ctx = vertx.getContext();
  7. try {
  8. ContextImpl.setContext(null);
  9. deploymentManager.undeployVerticle(deploymentID, result -> {
  10. if (result.succeeded()) {
  11. log.info("Successfully undeployed HA deployment " + deploymentID + "-" + dep.verticleIdentifier() + " as there is no quorum");
  12. addToHADeployList(dep.verticleIdentifier(), dep.deploymentOptions(), result1 -> {
  13. if (result1.succeeded()) {
  14. log.info("Successfully redeployed verticle " + dep.verticleIdentifier() + " after quorum was re-attained");
  15. } else {
  16. log.error("Failed to redeploy verticle " + dep.verticleIdentifier() + " after quorum was re-attained", result1.cause());
  17. }
  18. });
  19. } else {
  20. log.error("Failed to undeploy deployment on lost quorum", result.cause());
  21. }
  22. });
  23. } finally {
  24. ContextImpl.setContext((ContextImpl) ctx);
  25. }
  26. }
  27. }
  28. }
  29. }

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

  1. Logger logger = LoggerFactory.getLogger("my-log4j2-logger");
  2. String result = recording.execute(() -> {
  3. logger.info("hello");
  4. });
  5. assertTrue(result.contains("hello"));
  6. result = recording.execute(() -> {
  7. logger.info("exception", new NullPointerException());
  8. });
  9. assertTrue(result.contains("exception"));
  10. logger.info("hello {} and {}", "Paulo", "Julien");
  11. });
  12. assertTrue(result.contains("hello Paulo and Julien"));
  13. logger.info("hello {}", "vert.x");
  14. });
  15. String expected = "hello vert.x";
  16. logger.info("hello {} - {}", "vert.x");
  17. });
  18. assertTrue(result.contains("hello vert.x - {}"));
  19. logger.info("hello {} {}", "vert.x", "foo");
  20. });
  21. assertTrue(result.contains("hello vert.x foo"));
  22. logger.info("{}, an exception has been thrown", new IllegalStateException(), "Luke");
  23. });
  24. assertTrue(result.contains("Luke, an exception has been thrown"));

相关文章