dry-logger icon indicating copy to clipboard operation
dry-logger copied to clipboard

Dry::Logger ignores log-payloads passed by block

Open wuarmin opened this issue 2 years ago • 8 comments

I tried to plugin a Dry::Logger-instance at Faraday's logging middleware:

class MyRepo
  include Deps["logger"]

  def initialize(logger:)
    @logger = logger

    conn = Faraday.new(url: Ots::Slice[:settings].ots_endpoint) do |conn|
      conn.response :logger, logger
    end
  end
end

The resulting logs are:

[services] [INFO] [2023-01-11 09:49:53 +0100] request
[services] [INFO] [2023-01-11 09:49:53 +0100] request
[services] [INFO] [2023-01-11 09:49:53 +0100] response
[services] [INFO] [2023-01-11 09:49:53 +0100] response

instead of

[services] [INFO] [2023-01-11 09:49:53 +0100] request: POST https://www.api.de
[services] [INFO] [2023-01-11 09:49:53 +0100] request: bla bla bla 
[services] [INFO] [2023-01-11 09:49:53 +0100] response: Status 200
[services] [INFO] [2023-01-11 09:49:53 +0100] response: headers etc...

Faraday passes the log payload by block:

logger.info("request") { "hello" }

Is it expected that Dry::Logger differs from Ruby's Default Logger in this area? https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html#method-i-info

thanks and best regards

wuarmin avatar Jan 11 '23 09:01 wuarmin

This was an oversight. The intention is to have a compatible interface, so we gotta fix it.

solnic avatar Jan 12 '23 09:01 solnic

I am running into this same situation while using HTTP.rb.

komidore64 avatar Apr 27 '24 12:04 komidore64

:bulb: You might want to check out Cogger for this due to having block support built in by default. Cogger is similar in spirit to this gem's Object API but with a lot more features, customization, etc.

bkuhlmann avatar Apr 27 '24 14:04 bkuhlmann

@komidore64 Thanks for the nudge on this issue, I'll see if I can get a fix for you this week!

timriley avatar Apr 28 '24 11:04 timriley

@timriley hey that's great news! I was planning to take a crack at it in the next couple days, but I imagine I'll be slower coming to a solution as I'll have to get used to the codebase first.

Thanks for the quick reply <3

komidore64 avatar Apr 28 '24 11:04 komidore64

@komidore64 ohh, in that case, please be my guest! 😍

And instead, I can promise you some very prompt PR reviews. I'm also happy to answer questions. You can jump into our forum (which now has chat!) to reach me 😄

timriley avatar Apr 28 '24 11:04 timriley

ohh, in that case, please be my guest! 😍

Ok! I'll see what I can do.

And instead, I can promise you some very prompt PR reviews. I'm also happy to answer questions. You can jump into our forum (which now has chat!) to reach me 😄

Sounds great. Is your preference for me to reach out in the Hanami forum as opposed to dry-rb community forum? There is a (small, but) relevant thread in the dry-rb community space.

Regardless of communication location, I'm looking forward to working with you on this. Thanks a bunch!

komidore64 avatar Apr 28 '24 12:04 komidore64

Oh right, I had the wrong forum in mind when I linked that to you! If you have questions, happy for you to do so either here on this issue, or on the existing dry-rb forum thread. 😄

timriley avatar Apr 28 '24 13:04 timriley

@timriley do we need to trigger a job somewhere to get new documentation to appear for dry-logger on dry-rb.org?

komidore64 avatar Jun 01 '24 13:06 komidore64