This is a creation in Article, where the information may have evolved or changed.
Write a public function first, such as a method under the common package:
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 below:
- The tag, detailed, represents two string arguments for where the timeout occurred.
- Time the Start program started executing
- The TimeLimit function executes a timeout threshold in seconds.
When used, the first line of each function has the following code:
//
Func Save function name (...) (...) {
If this method executes for 3 seconds, the log is logged
Defer common. Timeoutwarning ("Saveapplogmain", "Total", time. Now (), float64 (3))
... The logic of the function itself.
}