ougai 0.7.1 → 0.7.2
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 +90 -2
- data/lib/ougai/formatters/readable.rb +9 -5
- data/lib/ougai/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab744df888b1db18e07decc89a6dfb1666a92d62
|
4
|
+
data.tar.gz: 89a0f4938fd5907d0aa82b9a8fcdfa8016b667b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3f8f5ebc280851c6df676f27b6de15d7bc55941c612182c885cb5348b26da3c1aa8c5efec861cdbc5f3cba08c46f0b80959adfd1810c388dbfdf28b14a8c0fc
|
7
|
+
data.tar.gz: 61f3eaa68945aff32a34677ab8b28f2ebaf66e6e1a7734b9e66e22c409f11c892799b9ef1a8ccb62dc7a8ef5b6a86f43455957c3ec1369b9be91fbf5ac4a17e8
|
data/README.md
CHANGED
@@ -145,7 +145,7 @@ end
|
|
145
145
|
```
|
146
146
|
|
147
147
|
|
148
|
-
|
148
|
+
## View log by node-bunyan
|
149
149
|
|
150
150
|
Install [bunyan](https://github.com/trentm/node-bunyan) via NPM
|
151
151
|
|
@@ -171,6 +171,7 @@ $ bunyan output.log
|
|
171
171
|
main.rb:18:in `<main>'
|
172
172
|
```
|
173
173
|
|
174
|
+
|
174
175
|
## Use human Readable formatter for console
|
175
176
|
|
176
177
|
Add awesome_print to Gemfile and `bundle`
|
@@ -191,7 +192,94 @@ logger.formatter = Ougai::Formatters::Readable.new
|
|
191
192
|
|
192
193
|
### Screen result example
|
193
194
|
|
194
|
-

|
195
|
+

|
196
|
+
|
197
|
+
|
198
|
+
## Use on Rails
|
199
|
+
|
200
|
+
### for Development
|
201
|
+
|
202
|
+
Add following code to `config/environments/development.rb`
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
Rails.application.configure do
|
206
|
+
...
|
207
|
+
|
208
|
+
logger = Ougai::Logger.new(STDOUT)
|
209
|
+
logger.formatter = Ougai::Formatters::Readable.new
|
210
|
+
config.logger = logger
|
211
|
+
end
|
212
|
+
```
|
213
|
+
|
214
|
+
### for Production
|
215
|
+
|
216
|
+
Add following code to the end block of `config/environments/production.rb`
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
Rails.application.configure do
|
220
|
+
...
|
221
|
+
|
222
|
+
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
223
|
+
config.logger = Ougai::Logger.new(STDOUT)
|
224
|
+
else
|
225
|
+
config.logger = Ougai::Logger.new(config.paths['log'].first)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
```
|
229
|
+
|
230
|
+
### With Lograge
|
231
|
+
|
232
|
+
You must modify [lograge](https://github.com/roidrage/lograge) formatter like *Raw*.
|
233
|
+
The following code set request data to `request` field of JSON.
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
Rails.application.configure do
|
237
|
+
config.lograge.enabled = true
|
238
|
+
config.lograge.formatter = Class.new do |fmt|
|
239
|
+
def fmt.call(data)
|
240
|
+
{ msg: 'Request', request: data }
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
```
|
245
|
+
|
246
|
+
### Output example on development
|
247
|
+
|
248
|
+
If you modify `application_controller.rb` as
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
class ApplicationController < ActionController::Base
|
252
|
+
protect_from_forgery with: :exception
|
253
|
+
|
254
|
+
def hello
|
255
|
+
logger.debug 'Call action', somefield: 'somevalue'
|
256
|
+
render plain: 'Hello!'
|
257
|
+
end
|
258
|
+
end
|
259
|
+
```
|
260
|
+
|
261
|
+
logger outputs
|
262
|
+
|
263
|
+
```
|
264
|
+
[2016-11-03T15:11:24.847+09:00] DEBUG: Call action
|
265
|
+
{
|
266
|
+
:somefield => "somevalue"
|
267
|
+
}
|
268
|
+
[2016-11-03T15:11:24.872+09:00] INFO: Request
|
269
|
+
{
|
270
|
+
:request => {
|
271
|
+
:method => "GET",
|
272
|
+
:path => "/",
|
273
|
+
:format => :html,
|
274
|
+
:controller => "ApplicationController",
|
275
|
+
:action => "hello",
|
276
|
+
:status => 200,
|
277
|
+
:duration => 30.14,
|
278
|
+
:view => 3.35,
|
279
|
+
:db => 0.0
|
280
|
+
}
|
281
|
+
}
|
282
|
+
```
|
195
283
|
|
196
284
|
## License
|
197
285
|
|
@@ -3,15 +3,19 @@ require 'ougai/formatters/base'
|
|
3
3
|
module Ougai
|
4
4
|
module Formatters
|
5
5
|
class Readable < Base
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
attr_accessor :plain, :trace_indent
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
super(opts[:app_name], opts[:hostname])
|
10
|
+
@trace_indent = opts[:trace_indent] || 4
|
11
|
+
@plain = opts[:plain] || false
|
9
12
|
load_awesome_print
|
10
13
|
end
|
11
14
|
|
12
15
|
def call(severity, time, progname, data)
|
13
16
|
msg = data.delete(:msg)
|
14
|
-
|
17
|
+
level = @plain ? severity : colored_level(severity)
|
18
|
+
strs = ["[#{time.iso8601(3)}] #{level}: #{msg}"]
|
15
19
|
if data.key?(:err)
|
16
20
|
err = data.delete(:err)
|
17
21
|
err_str = " #{err[:name]} (#{err[:message]}):"
|
@@ -19,7 +23,7 @@ module Ougai
|
|
19
23
|
strs.push(err_str)
|
20
24
|
end
|
21
25
|
unless data.empty?
|
22
|
-
strs.push(data.ai)
|
26
|
+
strs.push(data.ai({ plain: @plain }))
|
23
27
|
end
|
24
28
|
strs.join("\n") + "\n"
|
25
29
|
end
|
data/lib/ougai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ougai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshimitsu Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.5.1
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: JSON logger compatible with node-bunyan is capable of handling data easily.
|
102
102
|
test_files: []
|
103
|
-
has_rdoc:
|