maddy icon indicating copy to clipboard operation
maddy copied to clipboard

Migrate to standard library structured logging

Open foxcpp opened this issue 11 months ago • 1 comments

foxcpp avatar Jan 29 '25 22:01 foxcpp

Would a sensible starting point to be to switch to slog and include log levels for each call, and the module that is producing the line, whilst leaving the text and JSON extras that come at the end for improvement in a future commit? I think i might also be relevant to consider if log level co-ordinates with mail rejection/acceptance - for example, is a message rejected according to rules in the config, or a failed IMAP login attempt, a warning, information, an error? Would it make sense to keep the log level in a programmatic sense (error or warning means the code encountered a problem, such as failure to find an external authentication helper binary, DNS records couldn't be found, not able to open a socket to remote host) and separated from security level (authorised/not authorised) and message delivery (accepted, rejected, quarantined)? Or is this too complicated to filter through and should messages have a level representing an overall aggregate of how much it's an issue vs for informational purpooses?

I am guessing some structured logging might need a bit of thought - personally I'm looking to use something a bit more robust than just filtering in the terminal or what have you, and with my administrator cap on, things like filtering by address, inbound/outbound would be really useful for identifying the root cause of various problems - but at the same time, fields like these don't make sense for all modules. I am guessing most tools should be able to take in JSON and if I tell them that I want a specific column in a table, then if that key is missing from a line (as lines telling me the TLS keys were reloaded doesn't have a to/from address) it'll fill those in as null. But it somewhat raises the question of what keys should be in the root versus what keys are extra more detailed information (somewhat like the extended logging that is already present).

Lastly, I've noticed a bit of repetition in the log lines - e.g. things like {"mx": mx, "domain": domain}. I don't really know much about Go; I believe it offers some level of reflection and meta-programming, but this is the kind of thing in C++ where I'd use a macro to cut down repeated keystrokes. I don't know if something like that could be included.

stellarpower avatar Apr 17 '25 15:04 stellarpower