Closed Lupus closed 5 years ago
Okay, looks like I managed to figure out the appending at the end using kasprintf
and chaining one more continuation with original kfprintf
from the example. Probably I can encode the resulting message into json the same way, would that be the recommended option for json logging though?
Hm, I managed to wrap it up in json using the same approach. Sorry for the noise :)
@Lupus in case it helps, I developed a syslog reporter for Logs at https://github.com/hannesm/logs-syslog which works nicely for me (not yet RFC5424 structured syslog for tags due to some missing bits and pieces in https://github.com/verbosemode/syslog-message).
Cool, I'll take a look! Thanks.
I wanted to have fancy colourful text logging output when running my app interactively, but on the other hand nothing is better than json logs for production instance, so that they can be fed into Elastic or some other log processing system.
Also I wanted to embed some machine-readable fragments to each log message, in a form of json blob for simplicify, and have that added to the end of log messages when running interactively, and blend into log json object when running in production mode.
An example of what I'm trying to achieve:
Probably I need 2 reporters, one for human readable output, another for json. Structured metadata of reach message should probably be a tag with
Yojson.t
inside (does that sound sane?) I started implementing the first reporter, and got stuck at an attempt to add structured something (so far it's just a string tag for simplicity) to the end of the message. I'm followingtags.ml
test file as an example, and at line 33kfprintf
is curried with user-provided format string. If I add my%s
at the end of format string, that won't work. I was unable to wrap it in a way that does what I want. Any pointers are greatly appreciated, there's not much info on format magic in OCaml around.Also would be great to get a piece of advice on how to approach the json reporter...
Thanks in advance!