What are the skills of printing logs?

in daily development, we always encounter all kinds of anomalies. If there are anomalies, we need information to analyze and analyze, and the information usually comes from logs. In our company, some modules have a few G logs a day (too many). Some logs have one or two words (the information is too simple), how do you configure the log information in the production environment, how do you print it, and communicate

Mar.03,2021

self-written code, mature modules output to info level, newly written modules debug level, 99% of the possible problems are here.
other people's modules, just output warn.

here you refer to yourself or your team.
other people's home refers to systems and open source frameworks or tools.


the trick is:
do not log during high concurrency, or collect logs above info through the logging system.
it doesn't matter if it is not high concurrency.

when there is high concurrency, the problem is not located through the log at all. With so much traffic, how do you know which error is caused?


I like to split files by nature. Here is a simple example
http://www.itdfy.com/details/.


there are mainly two kinds of logs, error log and analysis log

errors are thrown by each module, and errors are handled uniformly at the top level, and error messages are output to the error log
Analysis log is generally used for statistics. Generally, there is only one request at a time, including all the information related to this request, including some statistical indicators

.

use github.com/sirupsen/logrus + github.com/sohlich/elogrus to collect logs to es, for statistical analysis based on es, and monitor alarms


what is said above is actually true. Let me also talk about some of my personal experience:
1. Do not print too many logs, but only print logs involving adding, modifying and deleting
2, thread names and lines of code should be printed with
3. It is best to type object attributes
4. Log of statistical type must be typed, for example, the execution time of a task, so the service becomes slow. You can quickly find


log classification: run log, operation log, interface log, etc.
different logs print information that requires different types of logs according to business requirements

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1beb9e9-31aa6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1beb9e9-31aa6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?