rack-colorized_logger 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack-colorized_logger.rb +26 -6
- metadata +2 -2
@@ -10,23 +10,34 @@ module Rack
|
|
10
10
|
:cookies => [:green, :magenta]
|
11
11
|
}
|
12
12
|
|
13
|
-
DEFAULT_OUTPUT =
|
13
|
+
DEFAULT_OUTPUT = STDOUT
|
14
14
|
|
15
|
-
attr_writer :public, :colors, :out
|
15
|
+
attr_writer :public, :colors, :out, :path, :assets
|
16
16
|
|
17
17
|
def initialize(app)
|
18
|
+
@app = app
|
19
|
+
|
20
|
+
if defined? Rails
|
21
|
+
@path = false
|
22
|
+
@public = ::File.join Rails.root, 'public'
|
23
|
+
@assets = '/assets'
|
24
|
+
else
|
25
|
+
@path = true
|
26
|
+
@public = nil
|
27
|
+
@assets = nil
|
28
|
+
end
|
29
|
+
|
18
30
|
yield self if block_given?
|
31
|
+
|
19
32
|
@colors ||= (defined? Rack::ColorizedLogger::COLORS) ? Rack::ColorizedLogger::COLORS : DEFAULT_COLORS
|
20
33
|
@out ||= DEFAULT_OUTPUT
|
21
|
-
@app = app
|
22
34
|
@public_map = Dir[::File.join(@public, '**', '*')].map {|f| ::File.basename f} if @public and ::File.directory? @public
|
23
35
|
end
|
24
36
|
|
25
37
|
def call env
|
26
38
|
@request = Rack::Request.new(env)
|
27
|
-
|
28
|
-
|
29
|
-
@out.puts "path:".bold + " " + @request.path
|
39
|
+
if not public_file? and not asset?
|
40
|
+
@out.puts "path:".bold + " " + @request.path if @path
|
30
41
|
@colors.each do |thing, color_a|
|
31
42
|
if thing.respond_to? :call
|
32
43
|
_thing = thing.call(@request)
|
@@ -38,11 +49,20 @@ module Rack
|
|
38
49
|
end
|
39
50
|
end
|
40
51
|
end
|
52
|
+
|
41
53
|
@app.call env
|
42
54
|
end
|
43
55
|
|
44
56
|
private
|
45
57
|
|
58
|
+
def public_file?
|
59
|
+
!@public_map.select {|p| @request.path.index(%{/#{p}}) == 0}.empty? if @public_map and not @public_map.empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def asset?
|
63
|
+
@request.path.index(@assets) == 0 unless @assets.nil?
|
64
|
+
end
|
65
|
+
|
46
66
|
def pretty_colors_h(hash, k_color, v_color = nil, padding = 1, start = true)
|
47
67
|
v_color ||= k_color
|
48
68
|
indent = padding + 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-colorized_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|