go_logger | Go logger wrapper
kandi X-RAY | go_logger Summary
kandi X-RAY | go_logger Summary
Go Logger wraper =. Usage - import "github.com/a2n/go_logger". logger.New("PREFIX ").Info("foo") logger.New("PREFIX ").Alert("foo") . Supported Levels - * Emerg * Alert * Crit * Err * Warning * Notice * Info * Debug.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of go_logger
go_logger Key Features
go_logger Examples and Code Snippets
Community Discussions
Trending Discussions on go_logger
QUESTION
I'm looking for a way to write to log a traceback stack in golang, but only some lines from it. As I see it, it could be done by splitting the result obtained from debug.Stack() into a slice of structures, which could be then easily parsed.
this is what I get now with this call "fmt.Println(string(debug.Stack()))":
...ANSWER
Answered 2020-Sep-04 at 14:01You are probably better off using runtime.Callers
to get the individual items rather than trying to parse the stack as bytes.
This is what github.com/pkg/errors
does here: https://github.com/pkg/errors/blob/master/stack.go#L163:1. You can see that runtime.Callers
is already capable of skipping some levels.
From the uintptr
needed you can see, this is quite low level. You should however be fine just copying callers
function and all it depends on over and use the StackTrace
function to get a more usable stack of individual Frame
s: https://github.com/pkg/errors/blob/master/stack.go#L155
The frames can then be enhanced to return the function name, file, line number etc. How to extract that information can be seen in the different private functions of the Frame
: https://github.com/pkg/errors/blob/master/stack.go#L23
I've done the same in our local errors package to be able to adjust how the stack is printed. This can be adjusted in the Format
function of a Frame
.
Note: maybe not the simplest solution as this exposes you to some low level stuff, but I'd prefer it anytime over parsing the already printed stack.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go_logger
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page