daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Feb 20th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### BELINGS IN lib/logger_proxy.rb
  2.  
  3. ##############
  4. ### Logger ###
  5. ##############
  6.  
  7. require 'logger'
  8.  
  9. class Logger
  10.  
  11.   def flush(*args)
  12.     return
  13.   end
  14.  
  15.   def <<(string = nil)
  16.     self.info(string)
  17.   end
  18.   alias :push :<<
  19.  
  20.   %w(debug info warn error fatal).each do |level|
  21.     eval <<-"end;"
  22.       def #{level}!(*args)
  23.         send(:#{level}, *args)
  24.       end
  25.     end;
  26.   end
  27.  
  28. end
  29.  
  30. ####################
  31. ### Logger Proxy ###
  32. ####################
  33.  
  34. class LoggerProxy
  35.  
  36.   attr_accessor :logger
  37.  
  38.   def initialize(*args)
  39.     @logger = self.class.initializer.call(self.class.logger, args)
  40.   end
  41.  
  42.   def method_missing(name, *args)
  43.     self.logger.send(name, *args)
  44.   end
  45.  
  46.   class << self
  47.     attr_accessor :logger, :initializer
  48.    
  49.     def setup(logger, &initializer)
  50.       self.logger = logger
  51.       self.initializer = initializer
  52.     end
  53.   end
  54.  
  55. end
  56.  
  57. #####################
  58. ### Install Proxy ###
  59. #####################
  60.  
  61. # Sets the Proxy's logger to the default Merb::Logger
  62. LoggerProxy.logger = Merb.send(:remove_const, :Logger)
  63.  
  64. # Merb::Logger.new(Merb.file, Merb::Config[:level], Merb::Config[:delimiter], Merb::Config[:auto_flush])
  65. LoggerProxy.initializer = lambda do |logger, (file, level, delimiter, auto_flush)|
  66.   logger.new(file, level, delimiter, auto_flush)
  67. end
  68.  
  69. # Sets the Merb::Logger to the LoggerProxy
  70. Merb::Logger = LoggerProxy
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top