 Why do we need logging in Java / Selenium?

Log4j is a logging framework, it is used as standard logger nowadays, as compared to System.out.println.
Log4j has certainly various advantages over System.out.println firstly being checking the output, the outputs to standard output which is mostly a console window whereas the output from Log4j can be to the console or email server, database table or a log file.
Additionally, in Log4j different levels of logging can be set such as TRACE, DEBUG, INFO, WARN, ERROR and FATAL. If a log level is set messages will be logged for that level and level below it.
Log4j allows logging on class-by-class basis i.e., each class can be covered whereas System.out.println can be controlled at application level. Though Log4j we can turn on or off the logging at runtime by changing the configuration file.
         Everybody who starts java starts with System.out.println() for printing message in java console. But this is not at all powerful as compared to advanced Java logging API like log4j and java.util.logging. If you are writing a java application server then only way to know what your server is doing is by seeing log file of your server. 
        suppose you don’t write anything in your java log file then nobody knows what your sever is doing, it becomes increasingly important if your application is connected to upstream and downstream like in many stock trading systems or electronic trading system and get input from upstream, transforms and normalize it and send down to downstream. In case of any issue without java logs you won’t be able to figure out what went wrong. That’s why logging in java is most important while writing any Java server application. Logging in Java is not by choice it’s must to understand.

Following are the Pros and Cons of Logging −

>  Logging is an important component of the software development. A well-written logging code offers quick debugging, easy maintenance, and structured storage of an application’s runtime information.
>  Logging does have its drawbacks also. It can slow down an application. If too verbose, it can cause scrolling blindness. To alleviate these concerns, log4j is designed to be reliable, fast and extensible.

> Since logging is rarely the main focus of an application, the log4j API strives to be simple to understand and to use

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -


Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories