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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/ougai/logger.rb +32 -24
- data/lib/ougai/version.rb +1 -1
- data/spec/logger_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19e44070a0143cd04e7b874389e53a46032065cb
|
4
|
+
data.tar.gz: 18dc7eb966f376c057a75a4e9fc3d243eff2d853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 631e1f0dea4f969cedef17930a09754ed3b3f00dbdeb306b38e572beffb82198c6d8aeb1d9eb81244221579094238c392d9feb46a1e465524a4b96ab6863e370
|
7
|
+
data.tar.gz: 51573402bd3bd1dc8e2f00d5d2d1d76dafc841bade69c2079425f8f03b9a380ee102af93cd0b45100977cf3edf0a2529713523d713933b2fbcd7889a9d25fa13
|
data/Gemfile.lock
CHANGED
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.
|
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(
|
105
|
+
def create_item_with_1arg(arg)
|
106
106
|
item = {}
|
107
|
-
if
|
108
|
-
item[:msg] =
|
109
|
-
set_exc(item,
|
110
|
-
elsif
|
111
|
-
item[: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
|
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(
|
119
|
+
def create_item_with_2args(arg1, arg2)
|
120
120
|
item = {}
|
121
|
-
if
|
122
|
-
item[:msg] =
|
123
|
-
set_exc(item,
|
124
|
-
elsif
|
125
|
-
item
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
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
|
+
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-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|