flogger icon indicating copy to clipboard operation
flogger copied to clipboard

how to customize the context

Open mokun opened this issue 6 years ago • 1 comments

Hi,

I'm new to flogger. Thanks for this wonderful fluent logger.

Currently, I use atMostEvery() often by calling logger.at(level).atMostEvery(time, TimeUnit.MILLISECONDS).log(message);

Is there's a way to customize the following context statement that are being appended to every log statement ?

[CONTEXT ratelimit_period="2000 MILLISECONDS [skipped: 2]" ] is a bit too verbose to my taste.

I'd like to shrink it down to just [2000,2].

I hope I'm making a very reasonable request here :D

Thanks for any help!

mokun avatar Dec 15 '18 01:12 mokun

Right now there isn't an easy way to customize this I'm afraid (it's part of the SimpleLoggerBackend, which is by design, as the name suggests, very simple). I do have some idea for a syntax to express log statement formatting (which I'd write a different backend for) and that would include a way to format metadata etc. in a more custom way.

It's a bit tricky in general though since anyone can provide metadata (via trace contexts) and the backend might not have any idea what to do with them other than calling toString() so there needs to be some "pluggable" way to define formats for specific metadata types. Then, of course, you start asking if it's really worth going to all that trouble.

I'll certainly bear this in mind when I do get the time to look at this properly.

hagbard avatar Dec 19 '18 12:12 hagbard