ougai 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60f1f030cbb1eb389906d56f3ecad6d4f0b549f2
4
- data.tar.gz: 602afdd55a5473b5a967269cb4b1d1b5b7251a8f
3
+ metadata.gz: ab744df888b1db18e07decc89a6dfb1666a92d62
4
+ data.tar.gz: 89a0f4938fd5907d0aa82b9a8fcdfa8016b667b2
5
5
  SHA512:
6
- metadata.gz: 0e33caabe88d4061539a7ac6b187f5280a78d00fd5eb93f6329f57ecf7eb699670f0c3708f67b56970b5ff6ca6f829b4856e2b42f74ae5e3a2b762ba7e94b1e6
7
- data.tar.gz: af162bcc83a5d6464c767c726b4e04af903c821303b151f02ed504cac3205e5b0f6b790e925b37a601e7149a4f37373e243e6db1ad29a352e894999adfd35e50
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
- ### View log by node-bunyan
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
- ![Screen Shot](https://github.com/tilfin/ougai/blob/images/ougai_readable_format.png?raw=true))
195
+ ![Screen Shot](https://github.com/tilfin/ougai/blob/images/ougai_readable_format.png?raw=true)
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
- def initialize(app_name = nil, hostname = nil)
7
- super(app_name, hostname)
8
- @trace_indent = 4
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
- strs = ["[#{time.iso8601(3)}] #{colored_level(severity)}: #{msg}"]
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
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
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.1
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-03 00:00:00.000000000 Z
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.2.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: