ougai 1.4.3 → 1.4.4

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: 056bac74cd408498f0fb9a5db5f8741094a201ac
4
- data.tar.gz: 7aec3907ebf359aa409a528a028605c8d4538281
3
+ metadata.gz: 07b9c78b3ba77163b4181b653717cde507c558c4
4
+ data.tar.gz: 24908f54426f4695ec3f3db02869de55bf239618
5
5
  SHA512:
6
- metadata.gz: d1fa397a69c767a637919f3891fba6c5e4a3edadb150483ffce4df6f5870c6f95bc28d33592438c1eabc71c4a2c7f23739e3ce2be8236ed733c65633561b2264
7
- data.tar.gz: d8a3ff21840a2d0fb328d12d2fd4f643b2512d3e2f55691d4fd0fcab7943b4f22c6e6248dd42aa603e5ff2abf7b0990c068d94a12ff9e7b1d8ccda1ce27f5a8c
6
+ metadata.gz: 123c9b422abdacaff15127779c162b211726e048d8b6f93840b31152a257865b550cfa8025131633553189544d66bf5b1072dbbb8f8fa97594d994cbfc160339
7
+ data.tar.gz: 57f93dda462f828a0130da70ca20b2f900680c74797e63670f71b294b43a1ae580b31a438b71cd122b02f46155f2ca7319cd8ba0e0b912abbd26d036d0d6371f
data/README.md CHANGED
@@ -6,9 +6,9 @@ Ougai
6
6
  [![Code Climate](https://codeclimate.com/github/tilfin/ougai/badges/gpa.svg)](https://codeclimate.com/github/tilfin/ougai)
7
7
  [![Test Coverage](https://codeclimate.com/github/tilfin/ougai/badges/coverage.svg)](https://codeclimate.com/github/tilfin/ougai/coverage)
8
8
 
9
- A structured JSON logging system is capable of handling a message, structured data or an exception easily.
10
- It is compatible with [Bunyan](https://github.com/trentm/node-bunyan) for Node.js.
11
- It can also output human readable format for the console.
9
+ A structured logging system is capable of handling a message, structured data or an exception easily.
10
+ It has JSON formatter compatible with [Bunyan](https://github.com/trentm/node-bunyan) for Node.js and
11
+ human readable formatter with [Awesome Print](https://github.com/awesome-print/awesome_print) for console.
12
12
 
13
13
  ## Installation
14
14
 
@@ -32,7 +32,8 @@ $ gem install ougai
32
32
 
33
33
  ## Usage
34
34
 
35
- **Ougai::Logger** is sub-class of original [Logger](https://docs.ruby-lang.org/ja/latest/class/Logger.html) in Ruby.
35
+ **Ougai::Logger** is sub-class of original [Logger](https://ruby-doc.org/stdlib-2.4.1/libdoc/logger/rdoc/Logger.html) in Ruby.
36
+ All arguments of the `initialize` pass through itself to **::Logger**.
36
37
 
37
38
  ```ruby
38
39
  require 'rubygems'
@@ -51,7 +52,7 @@ logger.info('Information!')
51
52
  {"name":"main","hostname":"mint","pid":14607,"level":30,"time":"2016-10-16T22:26:48.835+09:00","v":0,"msg":"Information!"}
52
53
  ```
53
54
 
54
- ### log only a data
55
+ ### log only structured data
55
56
 
56
57
  ```ruby
57
58
  logger.info({
@@ -277,9 +278,9 @@ logger.warn('Ignored something.')
277
278
  ```
278
279
 
279
280
 
280
- ## View log by node-bunyan
281
+ ## View logs with node-bunyan
281
282
 
282
- Install [bunyan](https://github.com/trentm/node-bunyan) via NPM
283
+ Install [bunyan](https://github.com/trentm/node-bunyan) via npm
283
284
 
284
285
  ```
285
286
  $ npm install -g bunyan
@@ -327,49 +328,12 @@ logger.formatter = Ougai::Formatters::Readable.new
327
328
  ![Screen Shot](https://github.com/tilfin/ougai/blob/images/ougai_readable_format.png?raw=true)
328
329
 
329
330
 
330
- ### Output example on development
331
+ ## How to use with famous products, services and libraries
331
332
 
332
- If you modify `application_controller.rb` as
333
-
334
- ```ruby
335
- class ApplicationController < ActionController::Base
336
- protect_from_forgery with: :exception
337
-
338
- def hello
339
- logger.debug 'Call action', somefield: 'somevalue'
340
- render plain: 'Hello!'
341
- end
342
- end
343
- ```
344
-
345
- logger outputs
346
-
347
- ```
348
- [2016-11-03T15:11:24.847+09:00] DEBUG: Call action
349
- {
350
- :somefield => "somevalue"
351
- }
352
- [2016-11-03T15:11:24.872+09:00] INFO: Request
353
- {
354
- :request => {
355
- :method => "GET",
356
- :path => "/",
357
- :format => :html,
358
- :controller => "ApplicationController",
359
- :action => "hello",
360
- :status => 200,
361
- :duration => 30.14,
362
- :view => 3.35,
363
- :db => 0.0
364
- }
365
- }
366
- ```
367
-
368
- ## How to use with famous products and libraries
369
-
370
- - [Use as Rails logger](https://github.com/tilfin/ougai/wiki/Use-as-Rails-logger)
333
+ - [Use as Rails logger](https://github.com/tilfin/ougai/wiki/Use-as-Rails-logger) and apply the request with [Lograge](https://github.com/roidrage/lograge)
371
334
  - [Customize Sidekiq logger](https://github.com/tilfin/ougai/wiki/Customize-Sidekiq-logger)
372
335
  - [Forward logs to Fluentd](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Fluentd)
336
+ - [Forward logs to Logentries](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Logentries)
373
337
 
374
338
  ## License
375
339
 
@@ -1,7 +1,9 @@
1
1
  module Ougai
2
+ # A logger created by the `child` method of parent logger
2
3
  class ChildLogger
3
4
  include Logging
4
5
 
6
+ # @private
5
7
  def initialize(parent, fields)
6
8
  @parent = parent
7
9
  @with_fields = fields
@@ -11,6 +13,7 @@ module Ougai
11
13
  @parent.level
12
14
  end
13
15
 
16
+ # @private
14
17
  def chain(severity, args, fields, hooks)
15
18
  hooks.push(@before_log) if @before_log
16
19
  @parent.chain(severity, args, merge_fields(@with_fields, fields), hooks)
@@ -3,6 +3,9 @@ require 'json'
3
3
 
4
4
  module Ougai
5
5
  module Formatters
6
+ # A JSON formatter compatible with node-bunyan
7
+ # @attr [Boolean] jsonize Whether log should converts JSON (by default this is on).
8
+ # @attr [Boolean] with_newline Whether tailing NL should be appended (by default this is on).
6
9
  class Bunyan < Base
7
10
  attr_accessor :jsonize, :with_newline
8
11
 
@@ -2,6 +2,10 @@ require 'ougai/formatters/base'
2
2
 
3
3
  module Ougai
4
4
  module Formatters
5
+ # A human readble formatter with awesome_print
6
+ # @attr [Boolean] plain Whether log should be plain not colorized (by default this is off).
7
+ # @attr [Fixnum] trace_indent The indent space size (by default this is 4).
8
+ # @attr [Array<String, Symbol>] excluded_fields The fields excluded from all logs.
5
9
  class Readable < Base
6
10
  attr_accessor :plain, :trace_indent, :excluded_fields
7
11
 
data/lib/ougai/logger.rb CHANGED
@@ -1,4 +1,9 @@
1
1
  module Ougai
2
+ # Main Logger
3
+ # @attr [String] default_message Use this if log message is not specified (by default this is 'No message').
4
+ # @attr [String] exc_key The field name of Exception (by default this is :err).
5
+ # @attr [Hash] with_fields The fields appending to all logs.
6
+ # @attr [Proc] before_log Hook before logging.
2
7
  class Logger < ::Logger
3
8
  include Logging
4
9
 
@@ -12,6 +17,8 @@ module Ougai
12
17
  @formatter = create_formatter
13
18
  end
14
19
 
20
+ # Broadcasts the same logs to the another logger
21
+ # @param logger [Logger] The logger receiving broadcast logs.
15
22
  def self.broadcast(logger)
16
23
  Module.new do |mdl|
17
24
  ::Logger::Severity.constants.each do |severity|
@@ -35,6 +42,7 @@ module Ougai
35
42
  end
36
43
  end
37
44
 
45
+ # @private
38
46
  def chain(severity, args, fields, hooks)
39
47
  hooks.push(@before_log) if @before_log
40
48
  write(severity, args, merge_fields(@with_fields, fields), hooks)
@@ -42,6 +50,7 @@ module Ougai
42
50
 
43
51
  protected
44
52
 
53
+ # @private
45
54
  def append(severity, args)
46
55
  hooks = @before_log ? [@before_log] : []
47
56
  write(severity, args, @with_fields, hooks)
@@ -51,6 +60,8 @@ module Ougai
51
60
  Formatters::Bunyan.new
52
61
  end
53
62
 
63
+ private
64
+
54
65
  def write(severity, args, fields, hooks)
55
66
  data = merge_fields(fields, to_item(args))
56
67
  hooks.each do |hook|
@@ -73,8 +84,6 @@ module Ougai
73
84
  end
74
85
  end
75
86
 
76
- private
77
-
78
87
  def create_item_with_1arg(msg)
79
88
  item = {}
80
89
  if msg.is_a?(Exception)
data/lib/ougai/logging.rb CHANGED
@@ -1,47 +1,76 @@
1
1
  module Ougai
2
+ # Common Logging features
2
3
  module Logging
3
4
  attr_accessor :with_fields
4
5
  attr_writer :before_log
5
6
 
7
+ # Log any one or more of a message, an exception and structured data as DEBUG.
8
+ # If the block is given for delay evaluation, it returns them as an array or the one of them as a value.
9
+ # @param message [String] The message to log. Use default_message if not specified.
10
+ # @param ex [Exception] The exception or the error
11
+ # @param data [Object] Any structured data
12
+ # @yieldreturn [String|Exception|Object|Array] Any one or more of former parameters
13
+ # @return [Boolean] true
6
14
  def debug(message = nil, ex = nil, data = nil, &block)
7
15
  log(Logger::DEBUG, message, ex, data, block)
8
16
  end
9
17
 
18
+ # Log any one or more of a message, an exception and structured data as INFO.
19
+ # @return [Boolean] true
20
+ # @see Logging#debug
10
21
  def info(message = nil, ex = nil, data = nil, &block)
11
22
  log(Logger::INFO, message, ex, data, block)
12
23
  end
13
24
 
25
+ # Log any one or more of a message, an exception and structured data as WARN.
26
+ # @return [Boolean] true
27
+ # @see Logging#debug
14
28
  def warn(message = nil, ex = nil, data = nil, &block)
15
29
  log(Logger::WARN, message, ex, data, block)
16
30
  end
17
31
 
32
+ # Log any one or more of a message, an exception and structured data as ERROR.
33
+ # @return [Boolean] true
34
+ # @see Logging#debug
18
35
  def error(message = nil, ex = nil, data = nil, &block)
19
36
  log(Logger::ERROR, message, ex, data, block)
20
37
  end
21
38
 
39
+ # Log any one or more of a message, an exception and structured data as FATAL.
40
+ # @return [Boolean] true
41
+ # @see Logging#debug
22
42
  def fatal(message = nil, ex = nil, data = nil, &block)
23
43
  log(Logger::FATAL, message, ex, data, block)
24
44
  end
25
45
 
46
+ # Log any one or more of a message, an exception and structured data as UNKNOWN.
47
+ # @return [Boolean] true
48
+ # @see Logging#debug
26
49
  def unknown(message = nil, ex = nil, data = nil, &block)
27
50
  args = block ? yield : [message, ex, data]
28
51
  append(Logger::UNKNOWN, args)
29
52
  end
30
53
 
54
+ # Creates a child logger and returns it.
55
+ # @param fields [Hash] The fields appending to all logs
56
+ # @return [ChildLogger] A created child logger
31
57
  def child(fields = {})
32
58
  ChildLogger.new(self, fields)
33
59
  end
34
60
 
61
+ # @private
35
62
  def chain(_severity, _args, _fields, _hooks)
36
63
  raise NotImplementedError
37
64
  end
38
65
 
39
66
  protected
40
67
 
68
+ # @private
41
69
  def append(severity, args)
42
70
  raise NotImplementedError
43
71
  end
44
72
 
73
+ # @private
45
74
  def merge_fields(base_data, new_data)
46
75
  base_data.merge(new_data) do |_, base_val, new_val|
47
76
  if base_val.is_a?(Array) and new_val.is_a?(Array)
data/lib/ougai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = "1.4.3"
2
+ VERSION = "1.4.4"
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: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshimitsu Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,8 +53,8 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description: |2
56
- A JSON logging system is capable of handling a message, data or an exception easily.
57
- It is compatible with Bunyan for Node.js and can also output human readable format for console.
56
+ A structured logging system is capable of handling a message, custom data or an exception easily.
57
+ It has JSON formatter compatible with Bunyan for Node.js and human readable formatter with Awesome Print for console.
58
58
  email:
59
59
  - toshi@tilfin.com
60
60
  executables: []
@@ -103,16 +103,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.5.1
106
+ rubygems_version: 2.6.11
107
107
  signing_key:
108
108
  specification_version: 4
109
- summary: JSON logger compatible with node-bunyan is capable of handling data easily.
109
+ summary: JSON logger compatible with node-bunyan is capable of handling structured
110
+ data easily.
110
111
  test_files:
111
- - spec/child_logger_spec.rb
112
112
  - spec/formatters/base_spec.rb
113
113
  - spec/formatters/bunyan_spec.rb
114
114
  - spec/formatters/readable_spec.rb
115
- - spec/logger_spec.rb
115
+ - spec/child_logger_spec.rb
116
116
  - spec/logging_spec.rb
117
+ - spec/logger_spec.rb
117
118
  - spec/ougai_spec.rb
118
119
  - spec/spec_helper.rb