It is always best to assume that every web or mobile app will have some undiscovered bugs that only a real user will unearth in production. And do not expect the user to report it. He will just abandon the app and leave. Imagine how many users you would lose because of these hard-to-discover bugs. Sending an app to production without adequate logging is like flying a plane without a black box. If it crashes, we will never know what happened. Logging is the only way to know what the user was doing before the bug occurred. Logs a like your repro steps.
On a related subject, product managers are also keen to know how users are using the product - which buttons they click often, what actions they take on dialogs, and so on. They need the ability to visualize user journeys on the product. And this requires the app to capture and record a continuous stream of user events.
Our logging playbook proposes a framework that attends to both - Logging and Tracking or aka App Logs and User Events.
At first, one needs to understand the difference between log collection and log transport.
A log collection is a class that collects all the logs that developers send from their code. It is a simple class
debug
: Debug logs that the developer might need for granular debugging. Log messages passed to debug
method are not always captured unless required for debugging a particular scenario. Because debug logs can be massive in numbers and almost have no value other than debugging a hard-to-reproduce issue. Eg:
function updateName(oldName, newName) {
logger.debug("Method updateName called with input params oldName: "+oldName+" and newName: "+newName);
}
info
: Info logs are the most important logs as they record all of the user actions plus any major task the app undertakes like calling an API. Info
logs are always streamed to all the log transports (more about transports later). Eg:
function delete(taskId) {
logger.info("Button clicked", { label: "delete", analyticsId: "btnDelete", taskId });
}
`