简体   繁体   English

Vert.x:登录文件的最佳方式

[英]Vert.x: best way to log to file

What is the fastest async way to log to file in Vert.x? 在Vert.x中以最快的异步方式登录文件是什么?

The aim is to write logs from loggers from different classes (ie Class1, Class2 etc) to 1 file (something like 'console.log') 目的是将来自不同类(即Class1,Class2等)的记录器的日志写入1个文件(类似'console.log')

Vert.x uses the JDK bundled JUL logging framework to avoid shipping additional dependencies. Vert.x使用JDK捆绑的JUL日志记录框架来避免传递其他依赖项。 However it allows to append a custom logger implementation. 但是,它允许附加自定义记录器实现。

Assuming that you want to stick to the default logging facility, customizing the log handler would then be as easy as droping a logging file and referencing it through the java.util.logging.config.file system property: 假设您希望坚持使用默认日志记录工具,那么自定义日志处理程序就像删除日志文件并通过java.util.logging.config.file系统属性引用它一样简单:

  • For example you can drop the logging configuration file under a config directory under the root path of your (fat) jar which may look as follows: 例如,您可以将日志配置文件放在(胖)jar的根路径下的config目录下,该路径可能如下所示:

     handlers = java.util.logging.MyFileHandler config = #... 
  • You should then refrence that file in a system property as follows when starting your Vert.x application: 然后,您应该在启动Vert.x应用程序时按如下方式在系统属性中引用该文件:

     -Djava.util.logging.config.file=config/logging.properties 
  • You can then access the Logger object in your classes as follows: 然后,您可以按如下方式访问类中的Logger对象:

     Logger logger = LoggerFactory.getLogger("some.package.MyClass"); 
  • Use that logger to log messages that will be handled by the configured handler(s): 使用该记录器记录将由配置的处理程序处理的消息:

     logger.info("some informative message"); 

Note the use of a custom log handler in the properties file to emphasis the possibily of appending your own handler (which may extend the default FileHandler ). 请注意在属性文件中使用自定义日志处理程序,以强调可能附加自己的处理程序(可能会扩展默认的FileHandler )。

Check the Vert.x documentation for more informations on how to use explore the logging feature . 有关如何使用探索日志记录功能的更多信息,请查看Vert.x文档。

Most of loggers are async from the beginning , ie they are not write information immediately. 大多数记录器从一开始就是异步的,即它们不是立即写入信息。 Logs are stored into buffer, which is flushed by timeout or when it is full. 日志存储在缓冲区中,缓冲区由超时或填满时刷新。 So slf4j + log4 is good enough for most cases. 所以slf4j + log4足以满足大多数情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM