shog 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -11
- data/docs/images/plain.png +0 -0
- data/docs/images/shogged.png +0 -0
- data/lib/shog/formatter.rb +192 -47
- data/lib/shog/formatters/defaults.rb +4 -1
- data/lib/shog/formatters/requests.rb +10 -2
- data/lib/shog/rails.rb +5 -2
- data/lib/shog/version.rb +1 -1
- data/lib/shog.rb +3 -0
- data/spec/lib/shog/formatter_spec.rb +80 -8
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d11bb673ce2d41a4d247e564223a567f17a3b327
|
4
|
+
data.tar.gz: c2f4489f6612357260fdfd8d5279ebaa53605c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cdb0e922b0536b88ff3ea00f8e4fce9fe5dd95ba54400e00cf103ef5cc506cead951f7f816be42724f967b3053dd6c874c32233e95dda8fbf7bedcba8c705b1
|
7
|
+
data.tar.gz: e18c58381f770385352b1ad7123c96fccf466b9e5122f07a9d2b755ba4ca67a9684d4e82abe815082f0e1657d30ada3d59adc73a72424caeb2aa6e010dee4119
|
data/README.md
CHANGED
@@ -2,32 +2,53 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/shog)
|
4
4
|
[](https://codeclimate.com/github/phallguy/shog)
|
5
|
-
[](https://gemnasium.com/phallguy/shog)
|
6
5
|
|
7
6
|
|
8
7
|
Make rails 4.0 log details more colorful.
|
9
8
|
|
10
9
|
There are plenty of logging frameworks for making tags (like timestamp, log
|
11
10
|
level, etc.) more colorful - but what about the details in the line of text?
|
12
|
-
What about the HTTP method used to make the request? What about the
|
11
|
+
What about the HTTP method used to make the request? What about the render
|
12
|
+
times?
|
13
13
|
|
14
|
-
|
14
|
+
Shog adds colors to highlight context and make it easier to pick out the
|
15
|
+
important parts of the message. Unformatted logs like this
|
15
16
|
|
16
|
-
|
17
|
+

|
17
18
|
|
18
|
-
|
19
|
+
become easy to ready and process logs like this
|
19
20
|
|
20
|
-
|
21
|
+

|
21
22
|
|
22
|
-
|
23
|
+
## Using Shog
|
23
24
|
|
24
|
-
|
25
|
+
Just add the following to your Gemfile to enable shiny output logs.
|
25
26
|
|
26
|
-
|
27
|
+
```
|
28
|
+
gem 'shog'
|
29
|
+
```
|
27
30
|
|
28
|
-
|
31
|
+
Shog comes built in with some sane defaults for rails apps. But you can
|
32
|
+
customize the output to match additional log message by your app, or to use
|
33
|
+
different options in production.
|
29
34
|
|
30
|
-
|
35
|
+
To change the defaults, add `shog.rb` to your `config/initializers` folder
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Shog.configure do
|
39
|
+
if ::Rails.env.production?
|
40
|
+
reset_config!
|
41
|
+
timestamp
|
42
|
+
end
|
43
|
+
|
44
|
+
match /execution expired/ do |msg,matches|
|
45
|
+
# Highlight timeout errors
|
46
|
+
msg.red
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
See [Shog::Formatter#configure](lib/shog/formatter.rb) for more configuration options.
|
31
52
|
|
32
53
|
## Contributing
|
33
54
|
|
Binary file
|
Binary file
|
data/lib/shog/formatter.rb
CHANGED
@@ -2,31 +2,43 @@ require 'active_support/tagged_logging'
|
|
2
2
|
require 'colored'
|
3
3
|
|
4
4
|
module Shog
|
5
|
+
|
6
|
+
# A rails logger formatter that spices up the log message adding color to
|
7
|
+
# and context to log messages.
|
8
|
+
#
|
9
|
+
# Shog automatically overrides the default formatter in your rails app. Use
|
10
|
+
# {Shog.configure} to configure the default logger.
|
5
11
|
class Formatter < ::ActiveSupport::Logger::SimpleFormatter
|
6
12
|
|
7
13
|
include ActiveSupport::TaggedLogging::Formatter
|
8
14
|
|
15
|
+
def initialize
|
16
|
+
reset_config!
|
17
|
+
end
|
18
|
+
|
19
|
+
# Called by the logger to prepare a message for output.
|
20
|
+
# @return [String]
|
9
21
|
def call( severity, time, progname, msg )
|
10
|
-
return if msg.blank?
|
11
|
-
tagged formatted_severity_tag( severity ) do
|
12
|
-
msg = formatted_message( severity, msg )
|
13
|
-
msg = timestamped_message( time, msg )
|
14
|
-
msg = prognamed_message( progname, msg )
|
22
|
+
return if msg.blank? || _silence?( msg )
|
15
23
|
|
16
|
-
|
17
|
-
|
18
|
-
|
24
|
+
msg = [
|
25
|
+
_tagged( time, :timestamp ),
|
26
|
+
_tagged( progname, :progname ),
|
27
|
+
formatted_severity_tag( severity ),
|
28
|
+
formatted_message( severity, msg )
|
29
|
+
].compact.join(" ")
|
19
30
|
|
20
|
-
|
21
|
-
reset_config!
|
31
|
+
super severity, time, progname, msg
|
22
32
|
end
|
23
33
|
|
24
|
-
# Formats the message according to the configured
|
34
|
+
# Formats the message according to the configured {#match} blocks.
|
35
|
+
#
|
25
36
|
# @param [String] msg to format.
|
37
|
+
# @return [String] the formatted message.
|
26
38
|
def formatted_message( severity, msg )
|
27
39
|
msg = String === msg ? msg : msg.inspect
|
28
40
|
|
29
|
-
if args =
|
41
|
+
if args = _matched( msg )
|
30
42
|
args.first.call msg, args.last
|
31
43
|
elsif proc = configuration[:severities][severity]
|
32
44
|
proc.call msg
|
@@ -37,6 +49,7 @@ module Shog
|
|
37
49
|
|
38
50
|
# Formats the severity indicator prefixed before each line when writing to
|
39
51
|
# the log.
|
52
|
+
#
|
40
53
|
# @param [String] the severity of the message (ex DEBUG, WARN, etc.)
|
41
54
|
# @return [String] formatted version of the severity
|
42
55
|
def formatted_severity_tag( severity )
|
@@ -44,16 +57,27 @@ module Shog
|
|
44
57
|
configuration[:severity_tags].reduce(0){ |l,(k,_)| [k.length,l].max }
|
45
58
|
end
|
46
59
|
|
60
|
+
return if length == 0
|
61
|
+
|
47
62
|
padded_severity = severity.ljust length
|
48
63
|
|
49
|
-
if proc = configuration[:severity_tags][severity]
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
formatted = if proc = configuration[:severity_tags][severity]
|
65
|
+
proc.call padded_severity
|
66
|
+
else
|
67
|
+
padded_severity
|
68
|
+
end
|
69
|
+
_tagged formatted, :severity_tags
|
54
70
|
end
|
55
71
|
|
56
|
-
# Formats a ms
|
72
|
+
# Formats a time value expressed in ms, adding color to highlight times
|
73
|
+
# outside the expected range.
|
74
|
+
#
|
75
|
+
# If `time` is more thatn `expected` it's highligted yellow. If it's more
|
76
|
+
# than double it's highlighted red.
|
77
|
+
#
|
78
|
+
# @param [String] time in ms.
|
79
|
+
# @param [Float] expected maximum amount of time it should have taken.
|
80
|
+
# @return [String] the formatted time.
|
57
81
|
def format_time( time, expected = 30 )
|
58
82
|
timef = time.to_f
|
59
83
|
case
|
@@ -67,57 +91,181 @@ module Shog
|
|
67
91
|
# ==========================================================================
|
68
92
|
# @!group Configuration
|
69
93
|
|
70
|
-
#
|
94
|
+
# Set up log message formatting for this formatter.
|
95
|
+
#
|
96
|
+
# @yield and executes the block where self is this formatter.
|
97
|
+
# @return [Formatter] self.
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# Formatter.new.configure do
|
101
|
+
# with :defaults
|
102
|
+
# timestamp
|
103
|
+
# severity(:error){ |msg| msg.red }
|
104
|
+
# severity(:fatal){ |msg| "\b#{msg}".red }
|
105
|
+
# end
|
71
106
|
def configure( &block )
|
72
107
|
instance_eval( &block )
|
73
108
|
self
|
74
109
|
end
|
75
110
|
|
76
|
-
# Format the severity tagged before each line.
|
77
|
-
|
78
|
-
|
111
|
+
# Format the severity indicator tagged before each line. To format the
|
112
|
+
# actual message itself use {#severity}.
|
113
|
+
#
|
114
|
+
# @overload severity_tag( level, proc )
|
115
|
+
# @param [String,Symbol] level to format.
|
116
|
+
# @param [#call(level)] proc that receives the log level and returns the
|
117
|
+
# reformatted level.
|
118
|
+
#
|
119
|
+
# @overload severity_tag( level )
|
120
|
+
# @param [String,Symbol] level to format.
|
121
|
+
# @yieldparam level [String] the log level to reformat.
|
122
|
+
# @yieldreturn [String] the reformatted level.
|
123
|
+
#
|
124
|
+
# @return [Formatter] self.
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# configure do
|
128
|
+
# severity_tag(:warn){|level| level.yellow }
|
129
|
+
# severity_tag(:error){|level| level.red }
|
130
|
+
# end
|
131
|
+
def severity_tag( level, proc = nil, &block )
|
132
|
+
proc ||= block
|
133
|
+
configuration[:severity_tags][ level.to_s.upcase ] = proc
|
134
|
+
self
|
79
135
|
end
|
80
136
|
|
81
|
-
# Provide
|
82
|
-
# a
|
83
|
-
#
|
84
|
-
|
85
|
-
|
137
|
+
# Provide default formatting for messages of the given severity when
|
138
|
+
# a {#match} is not found.
|
139
|
+
#
|
140
|
+
# @overload severity( level, proc )
|
141
|
+
# @param [String,Symbol] level to format.
|
142
|
+
# @param [#call(msg)] proc that receives the message and returns the
|
143
|
+
# reformatted message.
|
144
|
+
# @overload severity( level )
|
145
|
+
# @param [String,Symbol] level to format.
|
146
|
+
# @yieldparam msg [String] the message to reformat.
|
147
|
+
# @yieldreturn [String] the reformatted message.
|
148
|
+
#
|
149
|
+
# @return [Formatter] self.
|
150
|
+
#
|
151
|
+
# @example
|
152
|
+
# configure do
|
153
|
+
# severity(:fatal){ |msg| msg.white_on_red }
|
154
|
+
# end
|
155
|
+
def severity( level, proc = nil, &block )
|
156
|
+
proc ||= block
|
157
|
+
configuration[:severities][ level.to_s.upcase ] = proc
|
158
|
+
self
|
86
159
|
end
|
87
160
|
|
88
161
|
# Resets any previously configured formatting settings.
|
162
|
+
# @return [Formatter] self.
|
89
163
|
def reset_config!
|
90
164
|
@configuration ||= {
|
91
165
|
severity_tags: {},
|
92
166
|
severities: {},
|
93
|
-
matchers: {}
|
167
|
+
matchers: {},
|
168
|
+
silencers: []
|
94
169
|
}
|
95
170
|
self
|
96
171
|
end
|
97
172
|
|
98
|
-
#
|
99
|
-
#
|
100
|
-
|
101
|
-
|
173
|
+
# Re-format any log messages that match the given `pattern`.
|
174
|
+
#
|
175
|
+
# @overload match( pattern, proc)
|
176
|
+
# @param [Regexp] pattern to match against the log message.
|
177
|
+
# @param [#call(message,last_match)] proc a callable object that receives
|
178
|
+
# the message and the last match and re-formats the message.
|
179
|
+
#
|
180
|
+
# @overload match( pattern )
|
181
|
+
# @param [Regexp] pattern to match against the log message.
|
182
|
+
# @yieldparam message [String] the matched log message.
|
183
|
+
# @yieldparam last_match [MatchData] the regex matches.
|
184
|
+
# @yieldreturn [String] the re-formatted message.
|
185
|
+
#
|
186
|
+
# @example
|
187
|
+
# configure do
|
188
|
+
# match /GET (?<address>.*)/ do |message,last_match|
|
189
|
+
# "GETTING -> #{last_match['address'].green}"
|
190
|
+
# end
|
191
|
+
# end
|
192
|
+
# @return [Formatter] self.
|
193
|
+
def match( pattern, proc = nil, &block )
|
194
|
+
proc ||= block
|
195
|
+
configuration[:matchers][pattern] = proc
|
196
|
+
self
|
197
|
+
end
|
198
|
+
|
199
|
+
# When a log message matches the given `pattern` don't log it.
|
200
|
+
#
|
201
|
+
# @param [Regexp] pattern to match.
|
202
|
+
#
|
203
|
+
# @return [Formatter] self.
|
204
|
+
#
|
205
|
+
# @example
|
206
|
+
# configure do
|
207
|
+
# silence /assets\/bootstrap/
|
208
|
+
# end
|
209
|
+
def silence( pattern )
|
210
|
+
configuration[:silencers] << pattern
|
211
|
+
self
|
102
212
|
end
|
103
213
|
|
104
|
-
#
|
105
|
-
|
214
|
+
# Use configuration defined in the given module.
|
215
|
+
#
|
216
|
+
# @param [Symobl,#configure] mod the name of the shog module to use or an
|
217
|
+
# object that responds to `#configure`.
|
218
|
+
#
|
219
|
+
# @return [Formatter] self.
|
220
|
+
#
|
221
|
+
# When `mod` is a symobl, it loads one of the modules from
|
222
|
+
# {Shog::Formatters} and uses any configuration options sepcified in that
|
223
|
+
# module.
|
224
|
+
#
|
225
|
+
# Otherwise `mod` must respond to `#configure` taking a single argument -
|
226
|
+
# this formatter.
|
227
|
+
#
|
228
|
+
# @example Built-in Formatters
|
229
|
+
# configure do
|
230
|
+
# with :defaults
|
231
|
+
# with :requests
|
232
|
+
# end
|
233
|
+
#
|
234
|
+
# @example Custom Shared Formatters
|
235
|
+
# module MyFormatters
|
236
|
+
# def self.configure( formatter )
|
237
|
+
# formatter.configure do
|
238
|
+
# timestamp
|
239
|
+
# end
|
240
|
+
# end
|
241
|
+
# end
|
242
|
+
#
|
243
|
+
# configure do
|
244
|
+
# with MyFormatters
|
245
|
+
# end
|
246
|
+
def with( mod )
|
106
247
|
unless mod.is_a? Module
|
107
248
|
mod = "Shog::Formatters::#{mod.to_s.camelize}".constantize
|
108
249
|
end
|
109
250
|
|
110
251
|
mod.configure self
|
252
|
+
self
|
111
253
|
end
|
112
254
|
|
113
255
|
# Include timestamp in logged messages.
|
114
|
-
|
115
|
-
|
256
|
+
# @param [Boolean] enable or disable timestamping of log messages.
|
257
|
+
# @return [Formatter] self.
|
258
|
+
def timestamp( enable = true )
|
259
|
+
configuration[:timestamp] = enable
|
260
|
+
self
|
116
261
|
end
|
117
262
|
|
118
263
|
# Include the progname in logged messages.
|
119
|
-
|
120
|
-
|
264
|
+
# @param [Boolean] enable or disable tagging with the prog name of log messages.
|
265
|
+
# @return [Formatter] self.
|
266
|
+
def progname( enable = true )
|
267
|
+
configuration[:progname] = enable
|
268
|
+
self
|
121
269
|
end
|
122
270
|
|
123
271
|
# @!endgroup
|
@@ -126,7 +274,7 @@ module Shog
|
|
126
274
|
|
127
275
|
attr_accessor :configuration
|
128
276
|
|
129
|
-
def
|
277
|
+
def _matched( msg )
|
130
278
|
if matched = configuration[:matchers].find do |pattern,_|
|
131
279
|
pattern === msg
|
132
280
|
end
|
@@ -134,16 +282,13 @@ module Shog
|
|
134
282
|
end
|
135
283
|
end
|
136
284
|
|
137
|
-
def
|
138
|
-
return
|
139
|
-
|
140
|
-
"[#{time}] #{msg}"
|
285
|
+
def _tagged( val, config_key )
|
286
|
+
return unless configuration[config_key]
|
287
|
+
"[#{val}]"
|
141
288
|
end
|
142
289
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
"[#{progname}] #{msg}"
|
290
|
+
def _silence?( msg )
|
291
|
+
configuration[:silencers].any?{|p| p === msg }
|
147
292
|
end
|
148
293
|
end
|
149
294
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
module Shog
|
2
2
|
module Formatters
|
3
|
-
|
3
|
+
|
4
|
+
# Provide common default log formatting options.
|
4
5
|
module Defaults
|
5
6
|
module_function
|
6
7
|
|
8
|
+
# @see Shog::Formatter#configure
|
9
|
+
# @see Shog::Formatter#with
|
7
10
|
def configure( formatter )
|
8
11
|
formatter.configure do
|
9
12
|
severity_tag( :debug ) { |msg| msg.black.bold }
|
@@ -1,21 +1,28 @@
|
|
1
1
|
module Shog
|
2
2
|
module Formatters
|
3
|
-
#
|
3
|
+
# Provide common log formatting options for rails request logs such as
|
4
|
+
# controller names views, and render times.
|
4
5
|
module Requests
|
5
6
|
module_function
|
6
7
|
|
8
|
+
# @see Shog::Formatter#configure
|
9
|
+
# @see Shog::Formatter#with
|
7
10
|
def configure( formatter )
|
8
11
|
formatter.configure do
|
12
|
+
|
13
|
+
# Highlight HTTP request methods
|
9
14
|
match /Started\s+(?<method>PUT|PATCH|GET|POST|DELETE)\s+(?<path>"[^"]*")[^\d\.]+(?<ip>[\d\.]+)(?<time>.*)/ do |msg,match|
|
10
15
|
# http://refiddle.com/ge6
|
11
16
|
"#{match["method"].ljust 6} ".green.bold + " #{match["path"]} ".white.bold + " for " + "#{match["ip"]}".yellow + " #{match["time"]}".black.bold
|
12
17
|
end
|
13
18
|
|
19
|
+
# Dim detailed info about rendering views
|
14
20
|
match /\s*Rendered\s+(?<view>[^\s]+)\swithin\s(?<layout>[^\s]+)\s\((?<time>.*)\)/ do |msg,match|
|
15
21
|
# http://refiddle.com/18qr
|
16
|
-
" Rendered
|
22
|
+
" Rendered #{ match["view"] } within ".black + match["layout"].black.bold + " " + format_time( match['time'].black )
|
17
23
|
end
|
18
24
|
|
25
|
+
# Highlight the final rendered response
|
19
26
|
match /\s*Completed\s(?<code>\d+)\s(?<friendly>.*)\sin\s(?<time>\d+[^\s]*)\s(?<details>.*)/ do |msg,match|
|
20
27
|
# http://refiddle.com/18qq
|
21
28
|
parts = [ "Completed" ]
|
@@ -32,6 +39,7 @@ module Shog
|
|
32
39
|
parts.join(" ")
|
33
40
|
end
|
34
41
|
|
42
|
+
# Highlight the controller and action responding to the request
|
35
43
|
match /Processing by (?<controller>[^\s]*) as (?<format>.*)/ do |msg,match|
|
36
44
|
# http://refiddle.com/18qs
|
37
45
|
"Processing by #{match['controller'].magenta.bold} as #{match['format'].yellow}"
|
data/lib/shog/rails.rb
CHANGED
@@ -2,13 +2,16 @@ require 'rails'
|
|
2
2
|
|
3
3
|
module Shog
|
4
4
|
module Rails
|
5
|
+
|
6
|
+
# Automatically integrate Shog with the rails logger.
|
5
7
|
class Railtie < ::Rails::Railtie
|
6
8
|
config.before_initialize do
|
7
9
|
::Rails.logger.formatter = Shog::Formatter.new.configure do
|
8
|
-
|
9
|
-
|
10
|
+
with :defaults
|
11
|
+
with :requests
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
13
16
|
end
|
14
17
|
end
|
data/lib/shog/version.rb
CHANGED
data/lib/shog.rb
CHANGED
@@ -12,16 +12,70 @@ end
|
|
12
12
|
describe Shog::Formatter do
|
13
13
|
let(:formatter){ Shog::Formatter.new }
|
14
14
|
|
15
|
+
describe "#call" do
|
16
|
+
it "without configuration doesn't modify the request" do
|
17
|
+
output = formatter.call "TEST", Time.now, nil, "Unformatted"
|
18
|
+
expect( output ).to eq "Unformatted\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "adds severity when at least one is configured" do
|
22
|
+
formatter.severity_tag :debug, ->(msg){ msg }
|
23
|
+
output = formatter.call "DEBUG", Time.now, nil, "Tagged"
|
24
|
+
|
25
|
+
expect( output ).to eq "[DEBUG] Tagged\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "adds timestamp when configured" do
|
29
|
+
formatter.timestamp
|
30
|
+
output = formatter.call "WHEN", "just now", nil, "we missed them"
|
31
|
+
|
32
|
+
expect( output ).to eq "[just now] we missed them\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "adds progname when configured" do
|
36
|
+
formatter.progname
|
37
|
+
output = formatter.call "NAME", Time.now, "proggy", "magic"
|
38
|
+
|
39
|
+
expect( output ).to eq "[proggy] magic\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "adds them all" do
|
43
|
+
formatter.configure do
|
44
|
+
timestamp
|
45
|
+
progname
|
46
|
+
severity_tag :debug, ->(msg){ msg }
|
47
|
+
end
|
48
|
+
|
49
|
+
output = formatter.call "DEBUG", "NOW", "proggy", "gets them all"
|
50
|
+
expect( output ).to eq "[NOW] [proggy] [DEBUG] gets them all\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
15
54
|
describe "#formatted_severity_tag" do
|
16
55
|
it "buffers to the same size" do
|
17
56
|
formatter.severity_tag( :warn ){ |msg| msg }
|
18
57
|
formatter.severity_tag( :longer ){ |msg| msg }
|
19
58
|
|
20
|
-
expect( formatter.formatted_severity_tag( "WARN" ) ).to eq "WARN "
|
21
|
-
expect( formatter.formatted_severity_tag( "LONGER" ) ).to eq "LONGER"
|
59
|
+
expect( formatter.formatted_severity_tag( "WARN" ) ).to eq "[WARN ]"
|
60
|
+
expect( formatter.formatted_severity_tag( "LONGER" ) ).to eq "[LONGER]"
|
22
61
|
end
|
23
62
|
end
|
24
63
|
|
64
|
+
describe "#format_time" do
|
65
|
+
it "doesn't change when within expected" do
|
66
|
+
expect( formatter.format_time( "10ms".cyan, 30 ) ).to eq "10ms".cyan
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is yellow when above expected" do
|
70
|
+
expect( formatter.format_time( "50ms", 30 ) ).to eq "50ms".yellow
|
71
|
+
end
|
72
|
+
|
73
|
+
it "is red when way above expected" do
|
74
|
+
expect( formatter.format_time( "150ms", 30 ) ).to eq "150ms".red
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
25
79
|
describe "#match" do
|
26
80
|
it "formats a matched line" do
|
27
81
|
formatter.match /GET/ do |msg,match|
|
@@ -29,7 +83,7 @@ describe Shog::Formatter do
|
|
29
83
|
end
|
30
84
|
|
31
85
|
result = formatter.call "INFO", Time.now, nil, "Started GET \"/Home\""
|
32
|
-
expect( result ).to eq "
|
86
|
+
expect( result ).to eq "R'DONE\n"
|
33
87
|
end
|
34
88
|
|
35
89
|
it "includes the match" do
|
@@ -42,26 +96,44 @@ describe Shog::Formatter do
|
|
42
96
|
|
43
97
|
it "doesn't match" do
|
44
98
|
result = formatter.call "INFO", Time.now, nil, "Started GET \"/Home\""
|
45
|
-
expect( result ).to eq "
|
99
|
+
expect( result ).to eq "Started GET \"/Home\"\n"
|
46
100
|
end
|
47
101
|
|
48
102
|
it "uses default severity when no matcher is found" do
|
49
103
|
formatter.severity( :info ){ |msg| "DEFAULT" }
|
50
104
|
|
51
105
|
result = formatter.call "INFO", Time.now, nil, "Started GET \"/Home\""
|
52
|
-
expect( result ).to eq "
|
106
|
+
expect( result ).to eq "DEFAULT\n"
|
53
107
|
end
|
54
108
|
end
|
55
109
|
|
56
|
-
describe "#
|
110
|
+
describe "#silence" do
|
111
|
+
it "silences matching logs" do
|
112
|
+
formatter.silence /loud/
|
113
|
+
output = formatter.call "DEBUG", Time.now, nil, "I'm a really loud message"
|
114
|
+
expect(output).to be_nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#formatter" do
|
57
119
|
it "loads from a symbol" do
|
58
|
-
|
120
|
+
expect( Shog::Formatters::Spec).to receive :configure
|
121
|
+
|
122
|
+
formatter.configure do
|
123
|
+
with :spec
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "lods from a module" do
|
128
|
+
expect( Shog::Formatters::Spec).to receive :configure
|
59
129
|
|
60
130
|
formatter.configure do
|
61
|
-
|
131
|
+
with Shog::Formatters::Spec
|
62
132
|
end
|
63
133
|
end
|
64
134
|
end
|
65
135
|
|
66
136
|
|
137
|
+
|
138
|
+
|
67
139
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Alexander
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- Procfile
|
101
101
|
- README.md
|
102
102
|
- Rakefile
|
103
|
+
- docs/images/plain.png
|
104
|
+
- docs/images/shogged.png
|
103
105
|
- lib/shog.rb
|
104
106
|
- lib/shog/formatter.rb
|
105
107
|
- lib/shog/formatters.rb
|