github.com/OpsMx/go-app-base@v0.0.24/tracer/traceback.go (about) 1 // Copyright 2022 OpsMx, Inc 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tracer 16 17 import ( 18 "fmt" 19 "runtime" 20 ) 21 22 // Traceback returns a string showing the call path, used for debugging. 23 func Traceback() string { 24 pc := make([]uintptr, 15) 25 n := runtime.Callers(2, pc) 26 frames := runtime.CallersFrames(pc[:n]) 27 frame, _ := frames.Next() 28 return fmt.Sprintf("%s:%d %s\n", frame.File, frame.Line, frame.Function) 29 }