Logging is a very important part of deploying a production ready application. If you have more than 0 customers, it’s highly likely that something will break. How will you know something is broken? How will you know what broke it? How will you debug it? Let’s make this blog go from “explain me like I’m 5” to “just graduated Harvard”.
What is Logging?
When you are debugging a code, you must have put a console.log, print, fmt.Print or a printf statement, depending on your language. This way, if something goes wrong, you can look for that particular print statement in your terminal and debug the code.
This process of printing information on your terminal is called Logging (90% correct definition).
Why is Logging such a headache? Seems quite easy to me?
To understand this, let’s take an example of a findOrganisation function. The caller can pass an organisation ID and the function will return the organisation by fetching it from the database. Let’s say your function looks like this
async function getOrganisationById({ user, organizationId }: { user: User; organizationId: string }): Promise<Organization | null> {
if (user.isAdmin) {
return this.findOrganizationById({…