Why does writing logs is more important than what you think in software development?

Why-does-writing-logs-is-more-important-than-what-you-think-in-software-development large

Chances are you are interested in levelling up your skills as a programmer and decided to start finding topics you are interested to learn something new such as the importance of logging in programming.

Although that intro sentence sounds nice, most of programmers don’t really look for information about logging, especially entry-level programmers.

The reality is adding logs is not the sexiest topic to talk about. At the end, logging, as you can infer, is about inserting a record in a document whatever you want to see.

What would anyone research about logging?

Trust me, you want to read about this before you finish the development of your first project. No matter how many years of experience you have, this article should be helpful for you. Oftentimes seasoned programmers understand the value of logging, and I could see that happening. It took me about three years of my professional career as developer to start adding more logs in my projects.

Just to make sure, don’t go ahead and add a log for each single line of code in your app.

Please don’t.

It is not about adding more logs and magically becoming a better programmer. Also, you will likely get a pull request (PR) with full of comments about removing those logs.

Logging is essential aspect during the development of software. If you are a Junior developer, you might say logging is not necessary as you can always debug each line of code and gain a complete understanding of what is going on in an app, such as checking the values of the parameters passed to a function.

And to be honest that’s a valid argument. Why bother adding more lines of code with logs if you have previously debugged and verified the code is working correctly?

If you want to know why logging is important the hard way, go ahead and finish developing that project you’ve been working for months and publish it to production environment. Then, whenever you get users bombarding your customer service, aka your email, about unexpected errors they found in your app, we can go for a cup of coffee and have a time to talk about how you are going to quickly fix those unexpected bugs that even the QA team couldn’t find during the testing phase, and that is if you have enough budget to pay someone to test your project.

By the way, I meant a cup of hot chocolate as I’m not a coffee guy…

Back to the point.

If you don’t want to make such commitment of writing your whole app without writing logs, take this piece of advice: Add logs to your code. Skeptical about what I say? I would too. However, I have my arguments why writing logs is important for any programmer and must be part of any project.

Troubleshooting

If you are developer, you most likely have heard about deploying an application to different environments. Depending on the kind of project and company you work for, you will find different environments such as development, test, staging, and production. At the very least there has to one environment where your application is deployed: production. No matter the environment the application is deployed, you know there’s a point where you don’t have the ability to check step by step what is happening in an app, especially when bugs start happening and you need to take care of them as soon as possible.

By adding logs, you can quickly determine, at the very least get an idea of, why your application broke. Think about it, accessing log data allows you to attempt to replicate the same process an user was attempting to execute prior the crashing of your project. This might sound as common sense. However, when starting your journey as a programmer, you usually do not have to worry about troubleshooting production issues, unless you are the creator of a project. However, other developers will appreciate it without knowing who wrote logs at the beginning. Logging can make troubleshooting a breeze.

Monitoring

Did you think logs could give you the benefit of monitoring your app? Some might say you are already monitoring your app by checking the data that is used. Oftentimes database records hold information such as the date when a record was created, updated, or deleted, and the user who performed each action. However, you might be leaving a lot of information on the table that can be monitored. For example, you can add timestamps for every single log your application generates.

Using this information will allow you, i.e., to determine the times when most of the users are actively using an app, to keep track of the time a background process is executed from the beginning until its completion, or to understand the vulnerabilities of your code after a hacker attacked your app. At the end, logs provide data and as you have might have heard, data is king.

If we stick with one of the previous examples, i.e, to determine the times when most of the users are actively using an app, this will allow an experienced developer to develop an infrastructure that will adjust at specific times to meet the demand of current connections and maintain your app stability and performance without crashing because it cannot keep up with the demand.

Debugging

Certainly, software development is a process of constantly failing until you find the right solution to make an app work the way it supposed to work. During the development stage, not all the time you are debugging every single line of code when executing processes after adding new lines of code. Sometimes you get unexpected data being passed to a function you initially didn’t anticipate as part of your logic and all of the sudden your code breaks. Being able to quickly check the latest logs and get an idea of where the error is happening can save you time at the moment of adding the breakpoints and debugging to fix the bug.

All in all, I hope I made you realize the importance of logging in software development and see logging as an invaluable tool in your career. If I didn’t change your mind, hopefully you enjoy reading this article. Logging it is a simple concept, yet many don’t use it because they don’t see the value of it. Now, you are ready to rock and log!

Share this article or checkout our social media channels!