Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print the pkg/errors #895

Closed
virmundi opened this issue Jan 23, 2019 · 7 comments
Closed

How to print the pkg/errors #895

virmundi opened this issue Jan 23, 2019 · 7 comments

Comments

@virmundi
Copy link

How do I get the logger to print the stack trace from errors wrapped with pkg/errors?

What I've done so far is

  1. Create a new logger.
  2. Create an error wrapped with pkg/errors or created specifically from it.
  3. Used the WithError(...) feature
  4. Called entry.Error after chaining all of that.

All I see in the logs is the Error() string result. I do not see a stack trace.

I've searched around, but cannot find anything. Thank you.

@gguridi
Copy link

gguridi commented Jan 25, 2019

The problem lies within pkg/errors package, because stack is not accessible from outside.

Their Error() implementation only prints the message, ignoring the stack trace, and there's nothing we can do from logrus:
https://github.com/pkg/errors/blob/master/errors.go#L125

The only way to print the stack coming inside a pkg/errors error is by explicitly formatting it with %+v as shown here (but, and here's the thing, it will come also with the message :S):

logrus.WithField("message-and-stack", fmt.Sprintf("%+v", err)).Errorf("%v", err)

The only way I can think of bypassing the stack problem is creating your own error wrapper.

@virmundi
Copy link
Author

Thank you. I appreciate the official response.

@flimzy
Copy link
Contributor

flimzy commented Jan 27, 2019

The problem lies within pkg/errors package, because stack is not accessible from outside.

But it is, and the procedure is well documented.

@virmundi
Copy link
Author

You are purposely being obtuse. Ever other logging framework in every other language prints the full stack of an error when it gets on. Look at Slf4j. What I wanted is to get the full stack by only passing the error to WithError. Such a process does not exist.

If you did research you’d find a PR that people want for this tool, but are blocked by the interface. Please stop inserting yourself into topics you have no desire to fully appreciate.

@flimzy
Copy link
Contributor

flimzy commented Jan 27, 2019

@virmundi Are you replying to me? That's a very odd response to a comment in support of your issue, and offering a solution.

@virmundi
Copy link
Author

@flimzy please stop harassing me across the internet. As I’ve explained to you here and on SO, the question is how to use Logrus as one would use Slf4j, Apache common logging, or any other Loggong framework where stack traces are common.

As I noted on my SO answer, there is no native way for logrus do this. This is not a shortcoming of Logrus. Errors in Go are not exceptions like in Java. The answer you purpose leaks the abstraction of pkg/errors. The goal was to hook into Logrus behind the scenes to have it translate a pkg/error to a well formatted stack trace.

I closed this issue once it was made clear that Logrus does not support this feature. Please stop addressing this issue. You are not helping. You are harassing.

@flimzy
Copy link
Contributor

flimzy commented Jan 27, 2019

It's strange that you think offering help on an issue that affects us both is considered "harassment". That says a lot more about you than it does about my actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants