Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SemanticLogger is not working #320

Open
rade-tomovic opened this issue Jan 28, 2025 · 3 comments
Open

SemanticLogger is not working #320

rade-tomovic opened this issue Jan 28, 2025 · 3 comments
Assignees

Comments

@rade-tomovic
Copy link

I want to be able to use any logger. Currently, SemanticLogger is not working for no obvious reason.

     TypeError:
       Parameter 'logger': Expected type T.nilable(T.any(ActiveSupport::BroadcastLogger, Logger, Vonage::Logger)), got type SemanticLogger::Logger with hash 2142317253973070942
       Caller: /home/rade/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vonage-7.28.0/lib/vonage/config.rb:15
       Definition: /home/rade/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vonage-7.28.0/lib/vonage/config.rb:139 (Vonage::Config#logger=)

Config:

def client
      @client ||= Vonage::Client.new(
        api_key: ENV["VONAGE_API_KEY"],
        api_secret: ENV["VONAGE_API_SECRET"],
        logger: nil,
      ).sms
    end
@superchilled
Copy link
Contributor

Hi @rade-tomovic. Setting :logger to nil (as you have done in the Client options) should normally disable logging. Looking at the error, it seems like an issue with the Sorbet type signature for Config#logger, which is confusing because it should be nilable (see this line), so I'm not too sure what's happening here.

I'll need to investigate further. Will get back to you once I know more.

@superchilled superchilled self-assigned this Jan 31, 2025
@rade-tomovic
Copy link
Author

The only way to go around it is to monkey patch config with ugly overrides, but definitely not something I would like to use as solution for production - I would still like to use SemanticLogger as is.

# config/initalizers
# frozen_string_literal: true

module Vonage
  class SemanticLoggerAdapter < ::Logger
    def initialize(semantic_logger)
      @semantic_logger = semantic_logger
      super($stdout) # Parent needs an IO object but we won't use it
    end

    ::Logger::Severity.constants.each do |severity|
      define_method(severity.downcase) do |*args, &block|
        message = block_given? ? block.call : args.first
        @semantic_logger.send(severity.downcase, message)
      end
    end
  end

  class Config
    def logger=(logger)
      @logger = Logger.new(SemanticLoggerAdapter.new(logger))
    end
  end
end

@superchilled
Copy link
Contributor

@rade-tomovic sorry, I've not had a chance to look at this in depth yet. TBH I'm not familiar with SemanticLogger. I'll try and carve out some time over the next week or two to dig into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants