preface

When doing something, smart people think about the next three to five years, great people think about the next five to ten years, and really great people think about the next ten to twenty years.

The code you’re typing now may not be worth a dime ten years from now, but it’s never out of date to think about it.

Today I’m going to talk more about writing high-quality code.

The log

Now I really didn’t know that the book explained how to print logs in the system. It doesn’t seem redundant, and it doesn’t lose important information.

If something goes wrong in the production environment, the first thing we do is look at the production environment log to deal with the problem. If the production environment logs are not effectively printed at this time, other serious consequences can result. At best, it can delay solving problems, and at worst, it can lead to burnout.

So how do you print a proper log? At present with my shallow experience, can try from the following several angles.

Logs are generated during critical phases

Take an example of ordering in e-commerce system. The ordering process includes ordering completion, payment completion, logistics delivery, logistics arrival and other processes. At the very least, a specific log must be printed to represent each process after it starts and ends.

Invoke logs of other interfaces

Generally speaking, we are now distributed services that call remote interfaces to retrieve data. So, this data actually needs to print out the log content. Otherwise, when something goes wrong with this code, you won’t be able to see from the log whether the remote call went wrong.

The outermost interface invokes logs

The log of the outermost interface call has to be printed. From the log of the outermost interface call, we can clearly judge the data obtained by all the layers layer by layer, and finally deduce from these data exactly which line of code has the problem. Here, I personally feel that if the level is more, in the middle of this should also type the corresponding log information, to help reduce the logic of their judgment.

Error logs must be printed

Never eat the error log. Absolutely must throw out the mistake unceasingly, otherwise GG.

Print logs for error-prone areas

Recently, there is often a piece of data that is always fetched from the cache, not the database. However, if the cache is not updated at this time, it will result in stale data in the cache, which is prone to errors everywhere. Consider how you can tell from the log whether the operation is retrieving data from the cache or from the database.

Don’t debug too often

In general, during the development phase, you can deal with the inexplicable problems in the system through continuous debugging. However, try to minimize this process. Problems that you can’t see through logs can have serious consequences for you in a production environment.

About writing

From now on, I will write an article here every day, with no limit on subject matter, content or word count. Try to put your daily thoughts into it.

If this article has helped you, give it a thumbs up and even better follow it.

If none of these are available, write down what you want to say when you finish reading? Effective feedback and your encouragement are the biggest help to me.

And I’m going to pick up my blog. Welcome to visit and eat watermelon.

I’m shane. Today is August 29, 2019. Thirty-sixth day of the hundred day writing project, 36/100.