Tencent / TubeMQ

TubeMQ has been donated to the Apache Software Foundation and renamed to InLong, please visit the new Apache repository: https://github.com/apache/incubator-inlong
https://inlong.apache.org/
2.02k stars 391 forks source link

add log4j log configuration #47

Closed klboke closed 4 years ago

klboke commented 4 years ago

Add log4j log configuration for printing logs to the console during local development debugging


添加log4j日志配置以在本地开发调试期间将日志打印到控制台

klboke commented 4 years ago

https://github.com/Tencent/TubeMQ/issues/46

klboke commented 4 years ago

As I appealed, I think that printing INFO-level logs is my default requirement, so I only add it. And this configuration does not affect the results of the packaged program. What do you think? ? ?


正如我的诉求,我认为打印INFO级别的日志是我的默认需求,所以才增加。而且这个配置并不会影响打包后的程序的结果。你觉得呢???

klboke commented 4 years ago

The default is OFF, or without this configuration, I can't see anything on the console of the development tool, which will make the developer suspect the correctness of the program.


默认为OFF,或者没有这个配置,我在开发工具的控制台上什么都看不到,这会让开发者怀疑程序的正确性,如下图: image

tisonkun commented 4 years ago

As I appealed, I think that printing INFO-level logs is my default requirement, so I only add it. And this configuration does not affect the results of the packaged program. What do you think? ? ?

正如我的诉求,我认为打印INFO级别的日志是我的默认需求,所以才增加。而且这个配置并不会影响打包后的程序的结果。你觉得呢???

Recur my sentence,

so that developer by default won't be messed up by logs. Developer who want to debug with log can always turn on log level to INFO or DEBUG for his usage.

I don't think every developer want to enable full log by default(if tests or main method run as expected, why do I want to see that mess?). Besides, it is JUST a default value and when you want to turn on INFO or DEBUG log level, just do it. Here is another instance from FLINK community where it is a consensus for developers that when you want to enable full log for debugging, turn log level to INFO or DEBUG.

klboke commented 4 years ago

This also makes sense, changing some of my previous ideas.


这个也有道理,改变了我之前的一些想法

gosonzhang commented 4 years ago

This question can be resolved by Add new Configuration method: In Idea: Run--> Edit configuration --> Add new Configuration, select Application Set the Name to Tube_Master in Configuration tab: select Main class to com.tencent.tubemq.server.tools.MasterStartup In VM options, set the log4j.properties like this: -Dlog4j.configuration=file:E:\Git\TubeMQ\conf\tools.log4j.properties in Program arguments, set the master.ini path,like this: -f E:\Git\TubeMQ\conf\master.ini and then save and run

gosonzhang commented 4 years ago

I'll close this pr that it is not need changed.

klboke commented 4 years ago

I know that the log configuration under conf can be loaded by -Dlog4j.configuration, but this does not solve my problem. At first, I did this. Then I found that the configuration log under conf was not printed to the console, but was written to the specified file. I think in development mode, I don’t expect to go to the log file every time. Looking for log information, it is more desirable to see the information directly from the console, however, I want to complete this, but also a lot of effort to modify the log configuration, this is not what I want


我知道通过-Dlog4j.configuration的方式可以加载到conf下的日志配置,但是这并没解决我的问题。一开始我确实是这么做的,然后我发现conf下的配置日志都没有打印到控制台,而是写入到指定的文件了,我想在开发模式下,一定不期望每次都去日志文件中找日志信息吧,更期望的是直接从控制台中看到信息,然而,我想完成这个,还的费很大的劲去修改日志配置,这不是我想要的

gosonzhang commented 4 years ago

I understand the benefits of your setup. Here, the same configuration file is referenced as much as possible, mainly to reduce the number of configuration files in the project and reduce unnecessary configuration maintenance.


我理解你这样设置的好处,这里尽可能的引用同一个配置文件,主要是为了减少工程里的配置文件数量,减少不必要的配置维护。

klboke commented 4 years ago

That looks like a trade-off. I don't know how you did it during development. Write the file directly in the development log and view the information in the file. Or do you change this configuration file each time, and then change it back when you submit it? Compared to such a complicated operation, I prefer to add one more configuration, and the purpose of this file is obvious and does not require maintenance.


那这看起来像是一个取舍的问题,不知道你们在开发时是怎么做的,在开发日志直接写入文件,在文件中查看信息呢?还是每次修改这个配置文件,然后提交的时候又改回来呢?相比于这么复杂的操作,我是更倾向于多加一个配置,而且这个文件的目的也显而易见,也不需要维护

gosonzhang commented 4 years ago

If it is a windows environment, we use the above method, the log is output in the Idea Console; if it is a Linux environment, it will be directly output in the file, so there is no such problem. Log output we also have parameter configuration, multiple log configuration files are still not suitable for maintenance, after all, there is not much content.


如果是windows环境,我们就是采用上面方式进行,程序启动后日志会在Idea的Console里输出;如果是linux环境,直接就会在文件输出,所以没有这类问题出现。日志输出我们也是有参数配置的,多个日志配置文件维护起来还是不合适的,毕竟内容不多。