DEV: Connect pretty-text console to the Rails logger (#15909)
This will allow pretty text deprecations / errors / warnings to appear in the Rails logs, rather than disappearing silently. (implementation adapted from `discourse_js_processor.rb`)
This commit is contained in:
parent
0cda57f236
commit
a54a06fc41
|
@ -82,10 +82,18 @@ module PrettyText
|
|||
|
||||
ctx.eval("window = {}; window.devicePixelRatio = 2;") # hack to make code think stuff is retina
|
||||
|
||||
if Rails.env.development? || Rails.env.test?
|
||||
ctx.attach("console.log", proc { |l| p l })
|
||||
ctx.eval('window.console = console;')
|
||||
end
|
||||
ctx.attach("rails.logger.info", proc { |err| Rails.logger.info(err.to_s) })
|
||||
ctx.attach("rails.logger.warn", proc { |err| Rails.logger.warn(err.to_s) })
|
||||
ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) })
|
||||
ctx.eval <<~JS
|
||||
console = {
|
||||
prefix: "[PrettyText] ",
|
||||
log: function(...args){ rails.logger.info(console.prefix + args.join(" ")); },
|
||||
warn: function(...args){ rails.logger.warn(console.prefix + args.join(" ")); },
|
||||
error: function(...args){ rails.logger.error(console.prefix + args.join(" ")); }
|
||||
}
|
||||
JS
|
||||
|
||||
ctx.eval("__PRETTY_TEXT = true")
|
||||
|
||||
PrettyText::Helpers.instance_methods.each do |method|
|
||||
|
|
Loading…
Reference in New Issue