When starting the career of application developer in IT with one or more programming languages, one thing which is kept on back burner and kept for really long is logging. In fact, when I started my career as a programmer, when I realized that I wanted to know about what to log and what not to log, it was almost 4 years or so. This was my involvement in learning nitty-gritties of programming language itself, and not paying enough attention to logging at all. And, when I learnt most of it all, I realized how much value I added to programming by logging appropriate stuff in log files which was used for various different purpose during the execution of the software. One other challenge that comes with logging is what format to use for logging different kind of messages?
Before we go into what to log, lets see some general logging best practices in terms of usage of tools:
Lets try and see what are some of the minimum events which one would want to log:
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…
View Comments
2 remarks:
* first, talking about Java logging without mentionning SLF4J is an error. Without any specific requirements, you should use SLF4J by default. I mean, you want to be able to see the logs provided by the 3rd party libraries you will be using don't you ? You want to be able to switch easily from one implementation to another if needed ? So let's use SLF4J in the code and use any implementation that suits you (Logback, Log4J...)
* second point is the assertion that "Not all exceptions shall be logged". As the name states, "Exceptions" are meant to be... well... exceptional ! And by definition, when womething "exceptionnal" happens in your programm, you may want to have a way to know it. So my advice would be to log all exceptions by default. Maybe it would be better to just use a lower log level such as trace. Beleive me, when you're looking for the cause of a bug, you will curse the programmer that omit to log an exception that happen to be exactly what you were looking for.
Thanks for your comments, Francois.
+1 for SLF4J, and Logback blows Log4J away for speed, ease of use, configurations, and features; I'm migrating off Log4J as fast as I can.
Use logging levels and have a firm policy on what level of detail is present at each level, and do have useful debug and even trace logs, so that you can enable lots more detail live, when a knotty issue crops up.
Use at least class level loggers, never just one logger! Also allow external configuration of individual loggers, because you may want to see more detail in specific areas.
Learn about the logger configuration and important things like filtering, formatting, thread context logger variables. rolling logs, multiple logger targets etc.
Very useful comments. I personally have worked with both Log4J and Slf4J and found myself & my teams moving to Slf4J for various different advantages it brings on the table.