ppstack

package module
v0.0.0-...-a8f17d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

ppstack: Pretty print your golang stacktrace

Simple wrapper around panicparse to allow pretty printing at runtime for use by panic handlers, loggers, etc.

Automatically removes itself from the stacktraces.

Usage:

import (
    "github.com/pnegahdar/ppstack"
    "os"
)


func main(){
    ppstack.Print(os.Stdout, false) // set to true to print all gorounties.
}

E.g Logging in a grpc intercepter:

func unaryDebugIntercepter(enabled bool) grpc.UnaryServerInterceptor {
    return func (ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
        if !enabled {
            return handler(ctx, req)
        }
        resp, err := handler(ctx, req)
        if err != nil {
            ppstack.Print(os.Stdout, false)
        }
    return resp, err
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(target io.Writer, allRoutines bool) error

Types

type Palette

type Palette struct {
	EOLReset string

	// Routine header.
	RoutineFirst string // The first routine printed.
	Routine      string // Following routines.
	CreatedBy    string
	Race         string

	// Call line.
	Package                     string
	SrcFile                     string
	FuncMain                    string
	FuncLocationUnknown         string
	FuncLocationUnknownExported string
	FuncGoMod                   string
	FuncGoModExported           string
	FuncGOPATH                  string
	FuncGOPATHExported          string
	FuncGoPkg                   string
	FuncGoPkgExported           string
	FuncStdLib                  string
	FuncStdLibExported          string
	Arguments                   string
}

func (*Palette) BucketHeader

func (p *Palette) BucketHeader(b *stack.Bucket, pf pathFormat, multipleBuckets bool) string

BucketHeader prints the header of a goroutine signature.

func (*Palette) GoroutineHeader

func (p *Palette) GoroutineHeader(g *stack.Goroutine, pf pathFormat, multipleGoroutines bool) string

GoroutineHeader prints the header of a goroutine.

func (*Palette) StackLines

func (p *Palette) StackLines(signature *stack.Signature, srcLen, pkgLen int, pf pathFormat) string

StackLines prints one complete stack trace, without the header.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL