Skip to content

What, When and Why?

Estimated time to read: 2 minutes

from JUnit 5 Fundamentals

What is Logging?

Logging is the act of writing information about events in the appliation to either the console or to a file, known as a log file.

Logging occurs only when the application is running as it is reliant on the logging system within the application.

Certain events can be sent to the log file along with additonal messaging, this is decided by the developer who implements the logic. These events can include, but are not limited to:

  • Exceptions
  • Errors
  • Stacktraces

Why do we need Logging?

When something unexpected occurs in the application, it an be difficult to know what happened if no logging is in place.

Logging is extremley beneficial in the long term.

Troubleshooting

A good log will give a good understanding about what is happening within the application and when, this can help track down issues with the application.

Performance analytics

Keeping track of how well the application is performing can assist with identifying opportunities for imporvement and detect potential issues, before they turn into a problem in production.

Audting

Logging may also be a business requirement. Logs can be used during audits to explain what decision was made by the application, why, how and more.

When to use Logging?

Exceptions and Errors

When something goes wrong, logging an Exception or Error can help solve the problem.

Events and States

Informational logging from the complex diverse events and states within the application can be used to follow the path of the appliation and for performance analysis.

Debugging

Debug information is similar to Events and States, however it is specifically targeted for debugging an issue with the application.

HTTP Requests and Response

HTTP Requests and Responses, between internal applications can be logged, including either a full or partial capture of the data. If the application uses and External API, the Request and Response can again be captured.

Thread Usage

Along side performance analytics, Thread usage logs can be used to report deadlock issues, where two threads are blocked as they are waiting on each other.

Frontend Errors

Frontend Errors can be important to follow the path of the end user that generated the error and where it occured in the system.