tintoy / seqlog

Python logging integration for Seq (https://getseq.net)
https://seqlog.readthedocs.io/
MIT License
17 stars 11 forks source link

Can I fill the @x property using seqlog package when logging errors? #22

Closed vitekzach closed 5 years ago

vitekzach commented 5 years ago

Hi,

when I'm logging errors, I can include the traceback just fine, but I would like to fill the @x property of the underlying JSON body with it instead of just a generic one - is it possible short of using POST requests to achieve this?

tintoy commented 5 years ago

Hi - it’s been a while since I looked at that code, I’ll have a poke around and get back to you :)

tintoy commented 5 years ago

Ok, so I think you might be able to do what you want by sub-classing SeqLogHandler and overriding emit to modify the log entry properties as required.

From memory, the stack trace (if available) is called sinfo or stack_info.

tintoy commented 5 years ago

Oh, I see, @x is a root body property. No, I don't think there's a trivial way to do that the way the code is right now (I'd not seen that property when seqlog was first written).

@nblumhardt - do you know if older versions of Seq will accept log payloads that contain unrecognised properties on the root object in the payload?

I think we could probably modify seqlog to send @x if exc_info is available on the log record, but we might need to have some sort of switch to turn on this behaviour, if older versions of Seq won't accept requests whose body contains it

tintoy commented 5 years ago

Sorry, @nblumhardt, a simpler question if you please - what's the oldest version of Seq whose raw event-ingestion API supports the compact format (which is what I assume we're talking about when it comes to @x and friends)?

(I'm still on Seq v3.4 as the last paid version I can use, so I'd like to not break logging for myself if possible)

nblumhardt commented 5 years ago

Hi Adam! Seq versions from 3.3 onward supports compact format, and @x is understood from right back at that version, so on 3.4 this will be fine 👍

tintoy commented 5 years ago

Ok, thanks - will switch it over then! :)

tintoy commented 5 years ago

Ok, not using the compact format for now (bit of a PITA to serialise JSON line-by-line) but @x is equivalent to Exception so I've been able to still pass exception details to Seq if they're available.

Are you able to give 544438c a try? If it works for you, I'll publish it to PyPI

vitekzach commented 5 years ago

Amazing @tintoy , it does work! Do I understand it right exc_info has to be True? Does this work in only in an except block?

Thank you for the fix, it does work as expected for me. (and it helps to bring it up to the same level as other logging packages, as this is what our .NET apps logging to seq use to log errors by default).

tintoy commented 5 years ago

As I understand it, yes that’s the case. Or anything truthy at least.

I’ll get the package published tomorrow morning then :)

tintoy commented 5 years ago

Published v0.3.16 :-)

vitekzach commented 5 years ago

Works perfect, thank you so much! :)