Detailed Log Error Visualization

I am not really sure what to call this, so there may be an option here that I did not find in my research.

But is it possible to trigger same type of “expand to see more details” in a log sent to the gateway?

My use case is trace loggers that will show really large dynamic JSON, that I want to be able to leave the logs on for, but they will spam the page if they are not collapsed by default and it makes it hard to leave on that log without it making the logs difficult to work with.

I’m looking for the same “press the + icon to show more” functionality that’s used in errors like this

Nothing that’s not a bit hacky.

The details there are populated from the stacktraces attached to logged errors. So, the way to fake additional context…is to fake an exception with attached stacktrace.

So one option would be to make an instance of java.lang.Exception and call setStackTrace:[])
You’ll need to create your own StackTraceElements, but most of the arguments will be ignored in this use case so it’s pretty easy.

Sweet this is super close to what I was looking for!

With the code:

from java.lang import Throwable

logger = system.util.getLogger("DetailedEventTest")

myJson = system.util.jsonEncode(myObject)

myThrowable = Throwable(myJson)

# I do this to remove all of the stack trace elements that I dont want

logger.error("This is my message", myThrowable)

I tried doing this by creating a new stack trace element for each row in the json, but they would all start with "at " in the logs, so copying and pasting them was not the best. Any idea how I can remove that and just paste what I want there?

Making it the throwable message works fine because it can be copied, then you just have the trade-off of not being able to read it inside the log without pasting it somewhere else.

I think the at is added automatically somewhere in the chain and out of your control. At least, I remember having problems removing it the last time I explored this.

1 Like