groq-ruby icon indicating copy to clipboard operation
groq-ruby copied to clipboard

Allow IO/logger/proc as debugging configuration for all clients

Open drnic opened this issue 2 months ago • 0 comments

Currently to enable faraday logging to STDOUT, each Groq::Client needs a setup like:

    logger = Logger.new($stdout)
    logger.level = Logger::DEBUG

    @client = Groq::Client.new do |faraday|
      # Log request and response bodies
      faraday.response :logger, logger, bodies: true
    end

Perhaps we can have configuration for this, which provides a corresponding Groq::Client.new(&block).

Perhaps allow:

  • an IO:

    Groq.configuration do |c|
      c.logger = $stdout
    
  • a Logger:

    logger = Logger.new($stdout)
    logger.level = Logger::DEBUG
    
    Groq.configuration do |c|
      c.logger = logger
    
  • or a &faraday_middleware proc

    logger = Logger.new($stdout)
    logger.level = Logger::DEBUG
    faraday_middleware = proc do |faraday|
      # Log request and response bodies
      faraday.response :logger, logger, bodies: true
    end
    
    Groq.configuration do |c|
      c.faraday_middleware = faraday_middleware
    

These examples would all produce the same Proc that's provided to all Groq::Client instances.

If a Groq::Client.new(&block) was explictly provided, then a warning would be posted that the logger or faraday_middleware configuration is being ignored.

drnic avatar Apr 26 '24 20:04 drnic