Skip to content

Commit

Permalink
Console fix
Browse files Browse the repository at this point in the history
Update Logger#with_context and Logger#tagged to work correctly in console
  • Loading branch information
rsamoilov committed Feb 25, 2024
1 parent f4903fe commit d94e174
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/rage/logger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def tagged(tag)
private

def define_log_methods
console_mode = Rage.config.internal.rails_mode ? Rage.config.internal.rails_console : defined?(IRB)

methods = METHODS_MAP.map do |level_name, level_val|
if @logdev.nil? || level_val < @level
# logging is disabled or the log level is higher than the current one
Expand All @@ -123,7 +125,7 @@ def #{level_name}(msg = nil)
false
end
RUBY
elsif (Rage.config.internal.rails_mode ? Rage.config.internal.rails_console : defined?(IRB))
elsif console_mode
# the call was made from the console - don't use the formatter
<<-RUBY
def #{level_name}(msg = nil)
Expand Down Expand Up @@ -155,5 +157,17 @@ def #{level_name}(msg = nil)
end

self.class.class_eval(methods.join("\n"))

if console_mode
self.class.class_eval <<-RUBY
def with_context(_)
yield(self)
end
def tagged(_)
yield(self)
end
RUBY
end
end
end

0 comments on commit d94e174

Please sign in to comment.