First write a common function, for example, there is a method under the common package:
// Write timeout warning log General method func TimeoutWarning(tag, detailed string, start , timeLimit float64) { dis := ().Sub(start).Seconds() if dis > timeLimit { (log.CENTER_COMMON_WARNING, tag, " detailed:", detailed, "TimeoutWarning using", dis, "s") //pubstr := ("%s count %v, using %f seconds", tag, count, dis) //(tag, pubstr) } }
Several parameters of this function are described as follows:
tag and detailed two string parameters representing the location where the timeout occurs.
start time when the program starts execution
timeLimit The function execution timeout threshold, in seconds.
When using it, just have the following piece of code on the first line of each function:
// func SaveFunction name(…) (…) { // If this method executes for 3 seconds, the log will be recorded defer ("SaveAppLogMain", "Total", (), float64(3)) // … The logic of the function itself.}