Logging in CLI applications
While error handling is more of a “just-in-time” compensation mechanism when an unexpected event or error occurs, we may want to keep track of what happened so we can reproduce the issue, analyze it, understand why it happened in the first place, and fix it.
By “keeping track of what happened,” we either mean the sequence of events that led to that unexpected behavior or error and/or the call stack of the exception raised when the error occurred.
Selecting a logging format is important. We want to find a balance between the amount of data we are logging (and storing) and the usage we intend to do with it. Logging unnecessary information will complexify log analysis, increase storage (and retention) costs, and may also slow down the logging process. We will also need to ensure that we are not logging sensitive information (such as credit card data), and if we do, that we are doing it in a safe manner. Some of the popular...