First write a common function, such as under the common package there is a way:
Write Timeout warning Log general method
func timeoutwarning (tag, detailed string, start time.) Time, TimeLimit float64) {
dis: = time. Now (). Sub (Start). Seconds ()
if dis > timelimit {
log. Warning (log. Center_common_warning, Tag, "Detailed:", detailed, "timeoutwarning using", Dis, "s")
//pubstr: = FMT. Sprintf ("%s count%v, using%f seconds", tag, count, dis)
//stats. Publish (tag, pubstr)
}
}
Several parameters of this function are described as follows:
Tag, detailed two string parameters that indicate where the timeout occurred.
Time the Start program started executing
The TimeLimit function executes the timeout threshold in seconds.
When you use it, you have the following code in the first line of each function:
func Save function name (...) (...) {
//If this method performs a timeout of 3 seconds, log
defer common is logged. Timeoutwarning ("Saveapplogmain", "Total"), time. Now (), float64 (3))
//... The logic of the function itself.
}