Skip to content

Allow log level to be overridden per file #901

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/solargraph/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@ module Logging
@@logger.formatter = proc do |severity, datetime, progname, msg|
"[#{severity}] #{msg}\n"
end
@@dev_null_logger = Logger.new('/dev/null')


module_function

# override this in your class to temporarily set a custom
# filtering log level for the class (e.g., suppress any debug
# message by setting it to :info even if it is set elsewhere, or
# show existing debug messages by setting to :debug). @return
# [Symbol]
def log_level
:warn
end

# @return [Logger]
def logger
@@logger
if LOG_LEVELS[log_level.to_s] == DEFAULT_LOG_LEVEL
@@logger
else
new_log_level = LOG_LEVELS[log_level.to_s]
logger = Logger.new(STDERR, level: new_log_level)
logger.formatter = @@logger.formatter
logger
end
end
end
end