# How to log exception + stacktrace

**URL:** <https://forum.elixirforum.com/t/how-to-log-exception-stacktrace/2389>\
**Category:** Questions\
**Created:** [November 15, 2016, 3:17am UTC](https://forum.elixirforum.com/t/how-to-log-exception-stacktrace/2389 "2016-11-15T03:17:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbriggs](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mbriggs/32/1920_2.png) [@mbriggs](https://forum.elixirforum.com/u/mbriggs)\
**Post date:** [November 15, 2016, 3:17am UTC](https://forum.elixirforum.com/t/how-to-log-exception-stacktrace/2389/1 "2016-11-15T03:17:57Z")

</div>

Really having a hard time finding documentation around exception handling. Given `e` is the caught exception, I have tried

`Logger.error(e)`, but that gives me `** (Protocol.UndefinedError) protocol String.Chars not implemented`

`Exception.message(e)` gives me the message as a string, but what im looking for is message + formatted stacktrace.

I have seen `Exception.format_banner` which sounds like what i want, but Im not sure what the first param (`kind`) refers to

Thanks for the help 🙂

---

<div class="post-metadata">

**Author:** ![kelvinst](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kelvinst/32/10173_2.png) [@kelvinst](https://forum.elixirforum.com/u/kelvinst)\
**Post date:** [November 15, 2016, 9:31am UTC](https://forum.elixirforum.com/t/how-to-log-exception-stacktrace/2389/2 "2016-11-15T09:31:54Z")

</div>

You are in the right path with `Exception.format_banner/3`, but this function does not print the stacktrace. Instead, use `Exception.format/3`, and you will be good to go.

Now about the kind parameter, is basically one of this 3 options: `:error`, `:throw` or `:exit`. For exceptions catched with `try do ... rescue`, use the `:error` kind.

For more detail about it, look at the [try, catch and rescue guide](http://elixir-lang.org/getting-started/try-catch-and-rescue.html).

---

<div class="post-metadata">

**Author:** ![mike\_bianco](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mike_bianco/32/16307_2.png) [@mike\_bianco](https://forum.elixirforum.com/u/mike_bianco)\
**Post date:** [November 2, 2020, 1:29am UTC](https://forum.elixirforum.com/t/how-to-log-exception-stacktrace/2389/3 "2020-11-02T01:29:03Z")

</div>

I ran into a related problem. I wanted to log an exception with the correct metadata for it to be treated as an exception by error trackers like Sentry.

Here’s the solution I came up with:

[https://github.com/quantum-elixir/quantum-core/pull/464](https://github.com/quantum-elixir/quantum-core/pull/464)
