0

When starting my TCP server using Vertx, I have the following output :

[2018-06-04 12:15:45] [FINEST ] Net server listening on 0.0.0.0:/0:0:0:0:0:0:0:0:8600
[2018-06-04 12:15:45] [INFO   ] Server is now listening on port :  8600

I was expected the second line, since I am telling Vertx to write it :

    server.listen(res -> {
        if (res.succeeded()) {
            logger.info("Server is now listening on port : {0, number, #}", server.actualPort());
        }
        else {
            logger.error("Server failed to bind");
        }
    });

The first line though, is written by Vertx itself. I am bit surprised, since I could not see anywhere in Vertx documentation that this would happen nor how to prevent it from doing so.

How can I make Vertx stop logging automatically?

Thanks in advance.

souki
  • 1,305
  • 4
  • 23
  • 39

1 Answers1

1

Well, the manual states that vert.x by default uses java.util.logging, often referred to by its nickname JUL. It's configurable so depending on your use case you should be able to tune the log output. Alternatively vert.x can be instructed to use an external logging framework, they each have their own advantages and disadvantages.

The documentation for JUL isn't really the most helpful prose ever written, fortunately there are plenty of third party sites covering that topic, like http://tutorials.jenkov.com/java-logging/index.html but a quick Google will point you to many others too.

Resuming:

  • you will need to write a logging.properties file that reflects the output you want to obtain, and where (in logfiles and/or on the console)
  • you will have to pass that file to your vert.x application via the system property java.util.logging.config.file

Limiting the info produced by certain application parts can be done by using the filtering capabilities present in JUL. So, for example, in your logging.properties you could put

java.util.logging.FileHandler.level=INFO

which will restrict logging that goes to the logfile to INFO or higher. That like for example would already do away with the vert.x log you see in your example. You can also restrict logging per package, group of packages or even individual classes. A nice writeup of these possibilities can be found here: java.util.logging: how to set level by logger package (or prefix)? . I think vert.x uses the prefix io.vertx

fvu
  • 32,488
  • 6
  • 61
  • 79
  • I hope the edit makes it somewhat clearer - but as I said, it's not the best documented part of Java, which also explains why there are several alternative logging frameworks. But it's doable, and not piling up extra dependencies on your project can also have its advantages. – fvu Jun 04 '18 at 13:54
  • Yes I understood what you meant thanks to your edit. Thanks for your help :) – souki Jun 04 '18 at 13:55