Skip to content

Allow log level to be overridden per file#901

Open
apiology wants to merge 11 commits into
castwide:masterfrom
apiology:per_file_log_overriding
Open

Allow log level to be overridden per file#901
apiology wants to merge 11 commits into
castwide:masterfrom
apiology:per_file_log_overriding

Conversation

@apiology

@apiology apiology commented Apr 18, 2025

Copy link
Copy Markdown
Contributor

Useful for debug-level logging being turned on selectively at dev time

The idea here is that we could have code like this:

class SomeRandomClass
  def important_method
    data = logic
    logger.debug { "something happened: #{data}" }
    logic
  end
  
  include Logging
end

We can selectively turn on those debugging lines at dev time by temporarily adding a log_level method:

class SomeRandomClass

  def log_level
    :debug
  end
  
  def important_method
    data = logic
    logger.debug { "something happened: #{data}" }
    logic
  end
  
  include Logging
end

As a result, only the debug lines we care about are brought in while debugging something that interacts with SomeRandomClass

Useful for debug-level logging being turned on selectively at dev time
@apiology apiology marked this pull request as draft April 21, 2025 03:04
@apiology apiology marked this pull request as ready for review April 21, 2025 11:20
Comment thread lib/solargraph/logging.rb
# @return [Logger]
def logger
@@logger
if LOG_LEVELS[log_level.to_s] == DEFAULT_LOG_LEVEL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cache this as @logger here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant