Why you MUST Add Logger To your project?

hasanelsherbiny

Hasan Elsherbiny

Posted on December 21, 2023

Why you MUST Add Logger To your project?

When you start developing you application for sure you start with your ide which mostly has a built in debugger, when an error occurs you the debugger pauses the run of the application and tell you that an unexpected exception occurred, but the question here after fixing all bugs you have found "Is Your App Is Now Bug Free?"

the simple answer is "NO" there is no bug free application, so it's expected that on production your application can encounter bugs again but on this environment there is no debugger attached to tell you if there is an issue and where is it, so what to do?

it's really common to make good use of informer inside your app to keep track of it's happening , then when there is an error you can inspect this log and check what is going on.

Why you MUST Add Logger To your project?

as mentioned for a start you need your logger to log all un handled exceptions, but do we need to log only errors?

Log Levels

we have a lot of levels we can use depending on our situation and how important log is.

  1. TRACE : for extremely detailed and fine-grained information. Typically used during development and debugging to trace the flow of execution and inspect variable values.
    Example: Printing variable values, entering or exiting a method, etc.

  2. DEBUG: for messages that are helpful during development and debugging but are less detailed than trace messages. It provides insights into the application's internal state.
    Example: Displaying the state of key variables, logging method entry and exit points, etc.

  3. INFO: provide high-level information about the application's status and significant events. It is often used to track the flow of the application in production.
    Example: Startup messages, configuration details, significant state changes, etc.

  4. WARN: for messages that highlight potential problems that do not necessarily lead to errors. Warnings are often used to alert developers or administrators about conditions that may require attention.
    Example: Deprecated features, suboptimal configurations, non-fatal errors, etc.

  5. ERROR: for messages that represent errors or unexpected conditions that may impact the application's functionality. Errors generally indicate a failure but may not be fatal.

  6. FATAL: for critical errors that are so severe that they lead to the termination of the application. Fatal messages typically indicate a state from which the application cannot recover.
    Example: Unhandled exceptions, unrecoverable system failures, etc.

so logger is important for finding issues only?

actually no, you can use logger for other purposes ,such as

  • Monitoring and Performance Optimization
  • Auditing and Compliance
  • Understanding User Behavior
  • Long-Term Maintenance
  • Security Insights

in the end logger is your snitch inside the app converting it from a black box, having no idea what is happening there into an open book.

💖 💪 🙅 🚩
hasanelsherbiny
Hasan Elsherbiny

Posted on December 21, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related