Skip to content

stack2struct parses raw golang stack traces ([]byte) to a slice of well formated structs.

License

Notifications You must be signed in to change notification settings

kaeuferportal/stack2struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stack2struct

Build Status Coverage GoDoc

stack2struct parses raw golang stack traces ([]byte) to a slice of well formated structs.

Getting Started

Installation

  $ go get github.com/kaeuferportal/stack2struct

Usage

package main

import (
  "encoding/json"
  "fmt"
  "runtime"

  "github.com/kaeuferportal/stack2struct"
)

type stackTraceElement struct {
  LineNumber int    `json:"lineNumber"`
  ClassName  string `json:"className"`
  FileName   string `json:"fileName"`
  MethodName string `json:"methodName"`
}

type stackTrace []stackTraceElement

func (s *stackTrace) AddEntry(lineNumber int, packageName, fileName, methodName string) {
  *s = append(*s, stackTraceElement{lineNumber, packageName, fileName, methodName})
}

func main() {

  rawStackTrace := make([]byte, 1<<16)
  rawStackTrace = rawStackTrace[:runtime.Stack(rawStackTrace, false)]

  stack := make(stackTrace, 0, 0)
  stack2struct.Parse(rawStackTrace, &stack)

  enc, _ := json.MarshalIndent(stack, "", "\t")
  fmt.Println(string(enc))

}

should print

[
  {
    "lineNumber": 27,
    "className": "main",
    "fileName": "test.go",
    "methodName": "main()"
  }
]

Bugs and feature requests

Have a bug or a feature request? Please first check the list of issues.

If your problem or idea is not addressed yet, please open a new issue, or contact us at oss@kaeuferportal.de.

About

stack2struct parses raw golang stack traces ([]byte) to a slice of well formated structs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages