github.com/zhongdalu/gf@v1.0.0/g/util/gutil/gutil_debug.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  package gutil
     8  
     9  import (
    10  	"github.com/zhongdalu/gf/g/internal/debug"
    11  )
    12  
    13  // PrintStack prints to standard error the stack trace returned by runtime.Stack.
    14  func PrintStack(skip ...int) {
    15  	number := 1
    16  	if len(skip) > 0 {
    17  		number = skip[0] + 1
    18  	}
    19  	debug.PrintStack(number)
    20  }
    21  
    22  // Stack returns a formatted stack trace of the goroutine that calls it.
    23  // It calls runtime.Stack with a large enough buffer to capture the entire trace.
    24  func Stack(skip ...int) string {
    25  	number := 1
    26  	if len(skip) > 0 {
    27  		number = skip[0] + 1
    28  	}
    29  	return debug.Stack(number)
    30  }