Class: Rack::ColorizedLogger
- Inherits:
-
Object
- Object
- Rack::ColorizedLogger
- Defined in:
- lib/rack-colorized_logger.rb
Constant Summary collapse
- DEFAULT_COLORS =
{ :params => [:blue, :red], :session => [:cyan, :yellow], :cookies => [:green, :magenta] }
- DEFAULT_OUTPUT =
STDOUT
Instance Attribute Summary collapse
-
#assets ⇒ Object
writeonly
Sets the attribute assets.
-
#colors ⇒ Object
writeonly
Sets the attribute colors.
-
#out ⇒ Object
writeonly
Sets the attribute out.
-
#path ⇒ Object
writeonly
Sets the attribute path.
-
#public ⇒ Object
writeonly
Sets the attribute public.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) {|_self| ... } ⇒ ColorizedLogger
constructor
A new instance of ColorizedLogger.
Constructor Details
#initialize(app) {|_self| ... } ⇒ ColorizedLogger
Returns a new instance of ColorizedLogger.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rack-colorized_logger.rb', line 17 def initialize(app) @app = app if defined? Rails @path = false @public = ::File.join Rails.root, 'public' @assets = '/assets' else @path = true @public = nil @assets = nil end yield self if block_given? @colors ||= (defined? Rack::ColorizedLogger::COLORS) ? Rack::ColorizedLogger::COLORS : DEFAULT_COLORS @out ||= DEFAULT_OUTPUT @public_map = Dir[::File.join(@public, '**', '*')].map {|f| ::File.basename f} if @public and ::File.directory? @public end |
Instance Attribute Details
#assets=(value) ⇒ Object (writeonly)
Sets the attribute assets
15 16 17 |
# File 'lib/rack-colorized_logger.rb', line 15 def assets=(value) @assets = value end |
#colors=(value) ⇒ Object (writeonly)
Sets the attribute colors
15 16 17 |
# File 'lib/rack-colorized_logger.rb', line 15 def colors=(value) @colors = value end |
#out=(value) ⇒ Object (writeonly)
Sets the attribute out
15 16 17 |
# File 'lib/rack-colorized_logger.rb', line 15 def out=(value) @out = value end |
#path=(value) ⇒ Object (writeonly)
Sets the attribute path
15 16 17 |
# File 'lib/rack-colorized_logger.rb', line 15 def path=(value) @path = value end |
#public=(value) ⇒ Object (writeonly)
Sets the attribute public
15 16 17 |
# File 'lib/rack-colorized_logger.rb', line 15 def public=(value) @public = value end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rack-colorized_logger.rb', line 37 def call env @request = Rack::Request.new(env) if not public_file? and not asset? @out.puts "path:".bold + " " + @request.path if @path @colors.each do |thing, color_a| if thing.respond_to? :call _thing = thing.call(@request) @out.puts "#{_thing[0]}:".send(color_a[0]).bold pretty_colors_h _thing[1], *color_a else @out.puts "#{thing.to_s}:".send(color_a[0]).bold pretty_colors_h @request.send(thing), *color_a end end end @app.call env end |