Log4j vs. println for a simple convenient program

I wrote a small java program (50-60 lines) to help with my own development. It is called from the command line and basically downloads some files and decrypts them. It was not part of any product. I thought this might be useful for other developers in my group, so I sent it to check the code. The comment is back, I need to change System.out.println -s to log4j.

The output consists of the name of each downloaded file and the message after its completion.

Is this redundant? I think so.

+4
source share
4 answers

It seems you are asking for an opinion, which is likely to be marked for closing, but so far I agree, println is quite applicable. Debugging and informational messages, however, are usually sent to System.err, not System.out.

+2
source

If you want people to reuse your code, you will want to use some kind of journal. If you are going to use a logger, I recommend using SLF4J instead of log4j . This will allow some downstream developer using your code to use any logging infrastructure that they want to implement or has a binding for the SLF4J API (log4j, java.util.logging, logback, etc.).

If you don’t care about code reuse, and this is a standalone product, then yes, it may be redundant.

+1
source

Everything that you print in System.out will go to the “standard version”, you can redirect it to a file for further analysis, but it is very inflexible.

You cannot filter out what conforms to the standard if you use System.out ... everything will be printed. Using any logging infrastructure, such as SLF4J , Commons Recording, or you can use log4j, you can set different levels of logging.

Basically, you do not want to see every debug message. You can set various logging levels, such as WARNING , DEBUG , INFO using the logger.

0
source

It may be (overkill), but it depends.

When you say that the software was created for your own development, but then you released it to a group of developers, you actually say that the software originally had a function and now has a different function. Being the main function, you serve you and the secondary (and final function) group / community.

* If there are code standards in your development team , and I hope there are, and if one of the standards uses log4j to register everything, you certainly should go with the standards. *

0
source

Source: https://habr.com/ru/post/1392599/


All Articles