Flipped Coding

The Importance Of Log Files

learn more about The Importance Of Log Files
You’ve tried everything. There are all kinds of console.log message setup. Try-catch statements are everywhere. You’ve looked through the documentation, searched the forums from 2009, and still nothing. This isn’t a regular bug. It’s an advanced bug coming from an anonymous async function that has been hidden behind layers of a framework.

The only error you are getting is that there’s something wrong with the call. No Google search has been powerful enough to answer your questions and the other developers on your team have never seen this before. You’re on your own here. Until someone mentions checking the logs.

What are logs

Log files are automatically created to store a record of all the events from your application. Almost everything you use creates or adds to a log file. From the operating system your computer runs to the apps on your phone, they all make log files. They record things that you don’t normally track in your own error messages, like specific database columns that are causing errors.

It keeps track of every event that happens in your application from the minute you start running it to the second you stop it. Any calls you make to third party APIs or any scripts that run in the background will have a record here. This is your source for finding everything that happens behind the scenes of your application.

Why you need them

The reason we need logs is because they hold information that can’t be found anywhere else. For example, say you added something to a domain class but you forgot to run the migration. This will probably cause some problems. You don’t want to tell users that you are missing a certain column in your table for a lot of reasons.

An error like this will be recorded in the logs so that only someone with access to the server could see those kinds of errors. Most of the time this is where you should look when you can’t figure out what’s wrong with your code after hours of debugging. The answer might not always be here, but it will give you another place to go check.

Once you start looking in the log files when you have weird errors, it becomes easier to find ways to fix them. At the minimum, you will rule out another place to look. A lot of new developers don’t know about logs so it’s important that we take the time to teach them so they can learn how to better research bugs.

Tips about them

When you open a log file, it looks intimidating. It has thousands of lines and it all looks very technical and machine-y. Most of the stuff in the logs won’t matter to you. You just need to know what to look for. The majority of the time you’ll be checking your logs for errors and occasionally warnings.

Usually you’ll want to do a search for the word “error” when you open your logs. When you do that pay attention to the timestamp next to the error. You want to make sure you are looking at the most recent error that has been recorded. Also, make sure you have your logs configured in the beginning of a project. Some stuff gets recorded automatically, but if you want to look out for specific errors you’ll have to do some custom configuration.

Logs are these magical files that track errors we don’t even think of. Don’t be worried about how messy they look. Just search for the errors and then you might find something new to Google. Anybody else have some advice about logs?

Hey! You should follow me on Twitter because reasons: https://twitter.com/FlippedCoding