ougai 1.6.4 → 1.6.5

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: 023fe0a75fea490d495f73f3ba484240d1b9de15
4
- data.tar.gz: e91f1dbf146eafb6e889b2a8efd87e93c13da3c1
3
+ metadata.gz: 19e44070a0143cd04e7b874389e53a46032065cb
4
+ data.tar.gz: 18dc7eb966f376c057a75a4e9fc3d243eff2d853
5
5
  SHA512:
6
- metadata.gz: 27498f3e30636bc343f07d70c088c5801f72d859c93039505f7d566a5c73c0c4443486f6a3d2075ccae1dd7cee38fa009d64413b0d8f3f835e6bd07bd70c7752
7
- data.tar.gz: f6600fda8275ffd90f48a0720c768c64cc7d8e0e35c9992dd8d3c496910d64160a445525c53ad6ce0449068d2571d7b5192ec3e23be9ef1cbb93d71ee72e1b0d
6
+ metadata.gz: 631e1f0dea4f969cedef17930a09754ed3b3f00dbdeb306b38e572beffb82198c6d8aeb1d9eb81244221579094238c392d9feb46a1e465524a4b96ab6863e370
7
+ data.tar.gz: 51573402bd3bd1dc8e2f00d5d2d1d76dafc841bade69c2079425f8f03b9a380ee102af93cd0b45100977cf3edf0a2529713523d713933b2fbcd7889a9d25fa13
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ougai (1.6.4)
4
+ ougai (1.6.5)
5
5
  oj (~> 3.4)
6
6
 
7
7
  GEM
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  yard
49
49
 
50
50
  BUNDLED WITH
51
- 1.16.0
51
+ 1.16.1
data/README.md CHANGED
@@ -2,7 +2,7 @@ Ougai
2
2
  =====
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/ougai.svg)](https://badge.fury.io/rb/ougai)
5
- [![document](https://img.shields.io/badge/document-1.6.3-green.svg)](http://www.rubydoc.info/gems/ougai/1.6.3/)
5
+ [![document](https://img.shields.io/badge/document-1.6.4-green.svg)](http://www.rubydoc.info/gems/ougai/)
6
6
  [![Build Status](https://travis-ci.org/tilfin/ougai.svg?branch=master)](https://travis-ci.org/tilfin/ougai)
7
7
  [![Code Climate](https://codeclimate.com/github/tilfin/ougai/badges/gpa.svg)](https://codeclimate.com/github/tilfin/ougai)
8
8
  [![Test Coverage](https://codeclimate.com/github/tilfin/ougai/badges/coverage.svg)](https://codeclimate.com/github/tilfin/ougai/coverage)
data/lib/ougai/logger.rb CHANGED
@@ -102,46 +102,54 @@ module Ougai
102
102
  end
103
103
  end
104
104
 
105
- def create_item_with_1arg(msg)
105
+ def create_item_with_1arg(arg)
106
106
  item = {}
107
- if msg.is_a?(Exception)
108
- item[:msg] = msg.to_s
109
- set_exc(item, msg)
110
- elsif msg.is_a?(Hash)
111
- item[:msg] = @default_message unless msg.key?(:msg)
112
- item.merge!(msg)
107
+ if arg.is_a?(Exception)
108
+ item[:msg] = arg.to_s
109
+ set_exc(item, arg)
110
+ elsif arg.is_a?(String)
111
+ item[:msg] = arg
113
112
  else
114
- item[:msg] = msg.to_s
113
+ item.merge!(as_hash(arg))
114
+ item[:msg] ||= @default_message
115
115
  end
116
116
  item
117
117
  end
118
118
 
119
- def create_item_with_2args(msg, ex)
119
+ def create_item_with_2args(arg1, arg2)
120
120
  item = {}
121
- if ex.is_a?(Exception)
122
- item[:msg] = msg.to_s
123
- set_exc(item, ex)
124
- elsif ex.is_a?(Hash)
125
- item.merge!(ex)
126
- if msg.is_a?(Exception)
127
- set_exc(item, msg)
128
- else
129
- item[:msg] = msg.to_s
130
- end
121
+ if arg2.is_a?(Exception) # msg, ex
122
+ item[:msg] = arg1.to_s
123
+ set_exc(item, arg2)
124
+ elsif arg1.is_a?(Exception) # ex, data
125
+ set_exc(item, arg1)
126
+ item.merge!(as_hash(arg2))
127
+ item[:msg] ||= arg1.to_s
128
+ else # msg, data
129
+ item[:msg] = arg1.to_s
130
+ item.merge!(as_hash(arg2))
131
131
  end
132
132
  item
133
133
  end
134
134
 
135
135
  def create_item_with_3args(msg, ex, data)
136
- item = {}
137
- set_exc(item, ex) if ex.is_a?(Exception)
138
- item.merge!(data) if data.is_a?(Hash)
139
- item[:msg] = msg.to_s
140
- item
136
+ {}.tap do |item|
137
+ set_exc(item, ex) if ex.is_a?(Exception)
138
+ item.merge!(as_hash(data))
139
+ item[:msg] = msg.to_s
140
+ end
141
141
  end
142
142
 
143
143
  def set_exc(item, exc)
144
144
  item[@exc_key] = @formatter.serialize_exc(exc)
145
145
  end
146
+
147
+ def as_hash(data)
148
+ if data.is_a?(Hash) || data.respond_to?(:to_hash)
149
+ data
150
+ else
151
+ { data: data }
152
+ end
153
+ end
146
154
  end
147
155
  end
data/lib/ougai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = '1.6.4'
2
+ VERSION = '1.6.5'
3
3
  end
data/spec/logger_spec.rb CHANGED
@@ -128,6 +128,34 @@ describe Ougai::Logger do
128
128
  end
129
129
  end
130
130
 
131
+ context 'with data that can respond to_hash' do
132
+ it 'outputs valid' do
133
+ class Dummy
134
+ def to_hash
135
+ { foo: 1 }
136
+ end
137
+ end
138
+
139
+ logger.send(method, Dummy.new)
140
+ expect(item).to be_log_message('No message', log_level)
141
+ expect(item).to include_data(foo: 1)
142
+ end
143
+ end
144
+
145
+ context 'with data that cannot respond to_hash' do
146
+ it '(array) outputs valid' do
147
+ logger.send(method, ['bar', 2])
148
+ expect(item).to be_log_message('No message', log_level)
149
+ expect(item).to include_data(data: ['bar', 2])
150
+ end
151
+
152
+ it '(number) outputs valid' do
153
+ logger.send(method, 999)
154
+ expect(item).to be_log_message('No message', log_level)
155
+ expect(item).to include_data(data: 999)
156
+ end
157
+ end
158
+
131
159
  context 'with message and data' do
132
160
  it 'outputs valid' do
133
161
  logger.send(method, log_msg, data_id: 99, action: 'insert')
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.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshimitsu Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-18 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj