zalando/logbook

Logbook (spring starter RC) 3 appears to ignore "minimum status" and some strategies, strategies with "status-at-least"_ & "body-only-if-status-at-least"

darrenskywalker opened this issue · 12 comments

If I include in my application.yml :

minimum-status: 200
strategy: body-only-if-status-at-least

It appears to ignore the minimum status setting and log alll requests/responses regardless of it being set to 200(Like 400 statuses etc..) As well as it ignores the "body-only" part where it logs the whole request/response. However without-body works just fine etc..but obviously ignores the minimum-status part.

OR

minimum-status: 200
strategy: status-at-least

Similarly, It appears to ignore the minimum status setting and log alll requests/responses regardless of it being set to 200(Like 400 statuses etc..)

Maybe I understand the "minimum status" backwards from what it is. Because at minimum of "400" it doesn't log 200s which I would have expected it would.

So me personally, I only want to log 200 or successful requests.

It interprets the status numerically, i.e. a minimum status of 400 means the request/response pair is only logged if the status is >= 400.

If you want to see everything all the way down to 200, then just don't use minimum status, I'd say.

Yeah, I just want to only see or log 200s or "successes", so basically could we someday get a "maximum status" config option then? ie...299 and below ❤️

Or is there some other way for me to customize it, without making Logbook lib changes? ResponseFilter?

It looks like I'll need to customize my own sort of "conditions like org.zalando.logbook.Conditions? With some custom Predicates?

I also don't want to log GET requests as well so ... :)

Yeah, providing your own Strategy implementation is the quickest and most flexible route here.
You can take a look BodyOnlyIfStatusAtLeastStrategy for inspiration or as a blueprint.

Only 2xx is a pretty weird feature, to be honest.
I'd be surprised if there is any widespread desire for this, hence it probably won't make it into Logbook's core.

My opinion is that it's not weird but very useful in the case of considering an audit changelog...ie...only log requests that modified something in the DB. Showing the request and the outcome/response. before and after of the changes.

Huh, that's an interesting use case, true.

Thank you. Making a new Strategy looks like it'll work great for what I want!

@whiskeysierra ; real quick. I wrote my new Strategy which was simple...and I made a new Configuration file for it too to read from the application.yml.....does applicaiton.yml logbook section for Spring Boot able to read custom strategies there under the logbook section or do I need to do more manual LogBook configuration and not be able to use application.yml under the logbook section? I mean I know how to write configuration properties for Spring Boot project that are custom....but how is the "logbook section" able to see my new strategy property via application.yml or is that not possible? ie...maximum-status is just fine but the logbook section doesn't recognize the new strategy entry and I'm not sure if further customization will enable it via the logbook section in applicaiton.yml?

image

You can drop those two lines and register your strategy as a Spring bean, i.e. add a @Component annotation.
That should be enough for the auto configuration to find it and pick it up.

Thanks!

I've got it all working! It only logs successful & modifying requests....kind of like an audit change log. Thanks for your help @whiskeysierra !

It's basically an audit log for devs and not the end user