Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse is the main entry point for parsing stack traces
You can use this to parse stack traces from your code like this:
buf := make([]byte, 1<<16) runtime.Stack(buf, true) parsed := stackparse.Parse(buf) // use the parsed stack however you want // the return is also []byte, so you can do things like: os.Stderr.Write(parsed)
func ParseStatic ¶ added in v0.0.3
Use this to parse the stack trace in place overwriting the original buffer
buf := make([]byte, 1<<16) runtime.Stack(buf, true) stackparse.Parse(&buf) os.Stderr.Write(buf)
Types ¶
type Formatter ¶ added in v0.0.2
type Formatter struct {
// contains filtered or unexported fields
}
Formatter handles the formatting of parsed stack traces
func NewFormatter ¶ added in v0.0.2
NewFormatter creates a new Formatter instance
Mostly used internally, but exposed for some edge cases
func (*Formatter) Format ¶ added in v0.0.2
func (f *Formatter) Format(traces []*StackTrace) string
Format converts a StackTrace into a formatted string
If you are using this by itself without calling stackparse.Parse(), you should call this after the parser.
type Option ¶
type Option func(*Config)
Option is a function type for setting configuration options
func WithSimple ¶ added in v0.0.2
WithSimple enables or disables simplified output
type Parser ¶ added in v0.0.2
type Parser struct {
// contains filtered or unexported fields
}
Parser handles the parsing of stack traces
func NewParser ¶ added in v0.0.2
NewParser creates a new Parser instance with the given options
Mostly used internally but exposed for some edge cases
func (*Parser) Parse ¶ added in v0.0.2
func (p *Parser) Parse(stack []byte) []*StackTrace
Parse converts a byte slice containing a stack trace into a StackTrace
I you are usting this by itself and not by simply calling stackparse.Parse(), always call this before the formatter.
type Patterns ¶ added in v0.0.2
type Patterns struct { Goroutine *regexp.Regexp Function *regexp.Regexp Location *regexp.Regexp CreatedBy *regexp.Regexp LongFunc *regexp.Regexp }
Patterns holds all regex patterns used for parsing
type StackEntry ¶ added in v0.0.2
type StackEntry struct { FunctionName string FullName string Args string File string Line string Offset string IsCreatedBy bool CreatedByGoroutine string }
StackEntry represents a single entry in the stack trace
type StackTrace ¶ added in v0.0.2
type StackTrace struct { Entries []StackEntry GoroutineID string GoroutineState string }
StackTrace represents a complete stack trace
type StyleDisabler ¶ added in v0.0.3
type StyleDisabler interface {
DisableStyles()
}
StyleDisabler represents types that can disable their styles
type Theme ¶ added in v0.0.2
type Theme struct { Base lipgloss.Style Goroutine lipgloss.Style Function lipgloss.Style Args lipgloss.Style File lipgloss.Style Line lipgloss.Style CreatedBy lipgloss.Style Repeat lipgloss.Style // contains filtered or unexported fields }
Theme defines the styling for different components
You can provide you own theme to stackparse, and all of the output will be styled accordingly Setting a custom DisableStylesFunc is not required but if you want to preserve specific styling, you can do so. Usage would look something like this.
Method 1: Using SetDisableStylesFunc:
theme := stackparse.DefaultTheme() theme.SetDisableStylesFunc(func(t *stackparse.Theme) { // Custom implementation t.Base = t.Base.UnsetForeground() t.Function = t.Function.UnsetBold() // ... other custom unset operations })
Method 2: Creating a custom theme with custom disable function:
customTheme := &stackparse.Theme{ // ... theme settings ... } customTheme.SetDisableStylesFunc(func(t *stackparse.Theme) { // Custom implementation })
func DefaultTheme ¶ added in v0.0.2
func DefaultTheme() *Theme
DefaultTheme returns the default styling theme
func (*Theme) DisableStyles ¶ added in v0.0.3
func (t *Theme) DisableStyles()
DisableStyles disables all color and text styles (e.g. bold, underline, etc.) of a theme
When providing your own theme, you can use this default or create your own DisableStyles to unset only specific styling.
Keep in mind you need to reassign the styles after unsetting parts of them, for example:
func (t *Theme) DisableStyles() { t.Base = t.Base.UnsetForeground() }
func (*Theme) SetDisableStylesFunc ¶ added in v0.0.3
SetDisableStylesFunc allows setting a custom DisableStyles implementation
For more info read the documentation of
Theme{}