ougai 1.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02b6fb3d3c2a1bf4d395dcb2d1988230e6ec7d35
4
+ data.tar.gz: 4b839d8ec5c1a3ff40522532c37da50adb90b67a
5
+ SHA512:
6
+ metadata.gz: 5b5a2ad7ef4dcf1ce0778b66a788d0c9f21299d8188c0f9c8d6a4818c4b3c7d1d7e241c18aefba27d0c2b5aef3c5edf48ca6db84515c87fc701be2abd0a56fb8
7
+ data.tar.gz: a1873ff2005aa43c434a5a3563c28b08729e4308faf172b38c1799ea72e3e5cd06ef9aa07745ef6bf702fe86b4112d4bbb8d9e0f7ebac892f8a39c680095e9a7
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ougai.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'awesome_print'
8
+ gem 'simplecov', require: false
9
+ gem 'timecop'
10
+ gem 'yard'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ougai (1.7.1-java)
5
+ jrjackson (~> 0.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ awesome_print (1.8.0)
11
+ diff-lcs (1.3)
12
+ docile (1.3.1)
13
+ jrjackson (0.4.6-java)
14
+ json (2.1.0-java)
15
+ rake (10.5.0)
16
+ rspec (3.8.0)
17
+ rspec-core (~> 3.8.0)
18
+ rspec-expectations (~> 3.8.0)
19
+ rspec-mocks (~> 3.8.0)
20
+ rspec-core (3.8.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-expectations (3.8.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-mocks (3.8.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-support (3.8.0)
29
+ simplecov (0.16.1)
30
+ docile (~> 1.1)
31
+ json (>= 1.8, < 3)
32
+ simplecov-html (~> 0.10.0)
33
+ simplecov-html (0.10.2)
34
+ timecop (0.9.1)
35
+ yard (0.9.16)
36
+
37
+ PLATFORMS
38
+ java
39
+
40
+ DEPENDENCIES
41
+ awesome_print
42
+ bundler (~> 1.11)
43
+ ougai!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+ simplecov
47
+ timecop
48
+ yard
49
+
50
+ BUNDLED WITH
51
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Toshimitsu Takahashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,363 @@
1
+ Ougai
2
+ =====
3
+
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.7.0-green.svg)](http://www.rubydoc.info/gems/ougai/)
6
+ [![Build Status](https://travis-ci.org/tilfin/ougai.svg?branch=master)](https://travis-ci.org/tilfin/ougai)
7
+ [![Code Climate](https://codeclimate.com/github/tilfin/ougai/badges/gpa.svg)](https://codeclimate.com/github/tilfin/ougai)
8
+ [![Test Coverage](https://codeclimate.com/github/tilfin/ougai/badges/coverage.svg)](https://codeclimate.com/github/tilfin/ougai/coverage)
9
+
10
+ A structured logging system is capable of handling a message, structured data or an exception easily.
11
+ It has JSON formatters compatible with [Bunyan](https://github.com/trentm/node-bunyan) or [pino](https://github.com/pinojs/pino) for Node.js and
12
+ human readable formatter with [Awesome Print](https://github.com/awesome-print/awesome_print) for console.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'ougai'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```
31
+ $ gem install ougai
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ **Ougai::Logger** is sub-class of original [Logger](https://ruby-doc.org/stdlib-2.4.1/libdoc/logger/rdoc/Logger.html) in Ruby.
37
+ All arguments of the `initialize` pass through itself to **::Logger**.
38
+
39
+ ```ruby
40
+ require 'rubygems'
41
+ require 'ougai'
42
+
43
+ logger = Ougai::Logger.new(STDOUT)
44
+ ```
45
+
46
+ ### TRACE level
47
+
48
+ The `level` of logger supports **TRACE** level lower than **DEBUG**.
49
+
50
+ ```ruby
51
+ logger.level = Ougai::Logger::TRACE # , :trace or 'trace'
52
+ ```
53
+
54
+ ### log only a message
55
+
56
+ ```ruby
57
+ logger.info('Information!')
58
+ ```
59
+
60
+ ```json
61
+ {"name":"main","hostname":"mint","pid":14607,"level":30,"time":"2016-10-16T22:26:48.835+09:00","v":0,"msg":"Information!"}
62
+ ```
63
+
64
+ ### log only structured data
65
+
66
+ ```ruby
67
+ logger.info({
68
+ msg: 'Request', method: 'GET', path: '/login',
69
+ format: 'html', controller: 'LoginController',
70
+ action: 'new', status: 200
71
+ })
72
+ logger.debug(user: { name: 'Taro', age: 19 })
73
+ ```
74
+
75
+ ```json
76
+ {"name":"main","hostname":"mint","pid":9044,"level":30,"time":"2016-10-28T17:58:53.668+09:00","v":0,"msg":"Request","method":"GET","path":"/login","format":"html","controller":"LoginController","action":"new","status":200}
77
+ {"name":"main","hostname":"mint","pid":9044,"level":20,"time":"2016-10-28T17:58:53.668+09:00","v":0,"msg":"No message","user":{"name":"Taro","age":19}}
78
+ ```
79
+
80
+ If a data does not contain `msg` field, msg is set `default_message` attribute value of a Logger. its default is 'No message'.
81
+
82
+ ```ruby
83
+ logger.default_message = 'User dump'
84
+ logger.debug(user: { name: 'Taro', age: 19 })
85
+ ```
86
+
87
+ ```json
88
+ {"name":"main","hostname":"mint","pid":9303,"level":20,"time":"2016-10-28T18:03:50.118+09:00","v":0,"msg":"User dump","user":{"name":"Taro","age":19}}
89
+ ```
90
+
91
+ ### log only an exception
92
+
93
+ ```ruby
94
+ begin
95
+ raise StandardError, 'some error'
96
+ rescue => ex
97
+ logger.error(ex)
98
+ end
99
+ ```
100
+
101
+ ```json
102
+ {"name":"main","hostname":"mint","pid":4422,"level":50,"time":"2016-10-22T13:05:02.989+09:00","v":0,"msg":"some error","err":{"name":"StandardError","message":"some error","stack":"main.rb:24:in `<main>'"}}
103
+ ```
104
+
105
+ ### log with a message and custom data
106
+
107
+ ```ruby
108
+ logger.debug('Debugging', data_id: 1, data_flag: true)
109
+ logger.debug('Debug!', custom_data: { id: 1, name: 'something' })
110
+ ```
111
+
112
+ ```json
113
+ {"name":"main","hostname":"mint","pid":14607,"level":20,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Debugging","data_id":1,"data_flag":true}
114
+ {"name":"main","hostname":"mint","pid":14607,"level":20,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Debug!","custom_data":{"id":1,"name":"something"}}
115
+ ```
116
+
117
+ ### log with a message and an exception
118
+
119
+ ```ruby
120
+ begin
121
+ raise StandardError, 'fatal error'
122
+ rescue => ex
123
+ logger.fatal('Unexpected!', ex)
124
+ end
125
+ ```
126
+
127
+ ```json
128
+ {"name":"main","hostname":"mint","pid":14607,"level":60,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Unexpected!","err":{"name":"StandardError","message":"fatal error","stack":"main.rb:12:in `<main>'"}}
129
+ ```
130
+
131
+ ### log with an exception and custom data
132
+
133
+ ```ruby
134
+ begin
135
+ raise StandardError, 'some error'
136
+ rescue => ex
137
+ logger.error(ex, error_id: 999)
138
+ end
139
+ ```
140
+
141
+ ```json
142
+ {"name":"main","hostname":"mint","pid":13962,"level":50,"time":"2016-10-28T23:44:52.144+09:00","v":0,"error_id":999,"err":{"name":"StandardError","message":"some error","stack":"main.rb:40:in `<main>'"}}
143
+ ```
144
+
145
+ ### log with a message, an exception and custom data
146
+
147
+ ```ruby
148
+ begin
149
+ 1 / 0
150
+ rescue => ex
151
+ logger.error('Caught error', ex, reason: 'zero spec')
152
+ end
153
+ ```
154
+
155
+ ```json
156
+ {"name":"main","hostname":"mint","pid":14607,"level":50,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Caught error","err":{"name":"ZeroDivisionError","message":"divided by 0","stack":"main.rb:18:in `/'\n ...'"},"reason":"zero spec"}
157
+ ```
158
+
159
+ ### logs with blocks
160
+
161
+ ```ruby
162
+ logger.info { 'Hello!' }
163
+
164
+ logger.debug do
165
+ ['User dump', { name: 'Taro', age: 15 }]
166
+ end
167
+
168
+ logger.error do
169
+ ['Failed to fetch info', ex, { id: 10 }]
170
+ end
171
+
172
+ loggger.fatal { ex }
173
+
174
+ loggger.fatal do
175
+ ['Unexpected', ex]
176
+ end
177
+ ```
178
+
179
+ To specify more than one of a message, an exception and custom data, the block returns them as an array.
180
+
181
+ ### Adding custom fields to all logs
182
+
183
+ The fields of `with_fields` add to all logs as is.
184
+
185
+ ```ruby
186
+ logger.with_fields = { version: '1.1.0' }
187
+ logger.debug(user: { name: 'Taro', age: 19 })
188
+ logger.info('Hello!', user: { name: 'Jiro' }, version: '2.3')
189
+ ```
190
+
191
+ ```json
192
+ {"name":"test","hostname":"mint","pid":30182,"level":20,"time":"2017-07-22T20:52:12.332+09:00","v":0,"version":"1.1.0","msg":"No message","user":{"name":"Taro","age":19}}
193
+ {"name":"test","hostname":"mint","pid":30308,"level":30,"time":"2017-07-22T20:53:54.314+09:00","v":0,"version":"2.3","user":{"name":"Jiro"},"msg":"Hello!"}
194
+ ```
195
+
196
+ If any field of with_fields is specified in each log, the field is overridden.
197
+ But if the field's type is *Array*, both with_field value and logging value are merged with `concat` and `uniq`.
198
+
199
+ ### Create a child logger
200
+
201
+ `logger.child(with_fields)` creates a child logger of self. Its argument `with_fields` add to all logs the child logger outputs. A child logger can also create its child logger. If you pass a block to this method, the child logger will be yielded to it.
202
+
203
+ ```ruby
204
+ logger = Ougai::Logger.new(STDOUT)
205
+ logger.with_fields = { app: 'yourapp', tags: ['service'], kind: 'main' }
206
+
207
+ child_logger = logger.child({ tags:['user'], kind: 'logic' })
208
+ logger.info('Created child logger')
209
+
210
+ child_logger.info('Created a user', name: 'Mike')
211
+
212
+ gc_logger = child_logger.child({ kind: 'detail' })
213
+ child_logger.info('Created grand child logger')
214
+
215
+ gc_logger.debug('something detail', age: 34, weight: 72)
216
+
217
+ gc_logger.child({ mode: 'processed' }) do |gcc_logger|
218
+ gcc_logger.info('Great-grandchild logger that will be cleaned up on block exit.')
219
+
220
+ :some_return_value
221
+ end
222
+ ```
223
+
224
+ ```json
225
+ {"name":"main","hostname":"mint2","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service"],"kind":"main","msg":"Created child logger"}
226
+ {"name":"Mike","hostname":"mint2","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"logic","msg":"Created a user"}
227
+ {"name":"main","hostname":"mint2","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"logic","msg":"Created grand child logger"}
228
+ {"name":"main","hostname":"mint2","pid":8342,"level":20,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"detail","age":34,"weight":72,"msg":"something detail"}
229
+ {"name":"main","hostname":"mint2","pid":8342,"level":20,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"detail","mode":"processed","msg":"Great-grandchild logger that will be cleaned up on block exit."}
230
+ ```
231
+
232
+ If any field exists in both parent log and child log, the parent value is overridden or merged by child value.
233
+
234
+ ### Hook before logging
235
+
236
+ Setting `before_log` of logger or child an *lambda* with `data` field, a process can be run before log each output.
237
+
238
+ * Adding variable data (like Thread ID) to logging data can be defined in common.
239
+ * Returning `false` in *lambda*, the log is cancelled and does not output.
240
+ * The *before_log* of child logger is run ahead of the parent logger's.
241
+
242
+ ```ruby
243
+ logger.before_log = lambda do |data|
244
+ data[:thread_id] = Thread.current.object_id.to_s(36)
245
+ end
246
+
247
+ logger.debug('on main thread')
248
+ Thread.new { logger.debug('on another thread') }
249
+ ```
250
+
251
+ ```json
252
+ {"name":"main","hostname":"mint","pid":13975,"level":20,"time":"2017-08-06T15:35:53.435+09:00","v":0,"msg":"on main thread","thread_id":"gqe0ava6c"}
253
+ {"name":"main","hostname":"mint","pid":13975,"level":20,"time":"2017-08-06T15:35:53.435+09:00","v":0,"msg":"on another thread","thread_id":"gqe0cb14g"}
254
+ ```
255
+
256
+ ### Using broadcast, log output plural targets
257
+
258
+ `Ougai::Logger.broadcast` can be used to like `ActiveSupport::Logger.broadcast`.
259
+
260
+ #### An example
261
+
262
+ Original `logger` outputs STDOUT and `error_logger` outputs `./error.log`.
263
+ Every calling for `logger` is propagated to `error_logger`.
264
+
265
+ ```ruby
266
+ logger = Ougai::Logger.new(STDOUT)
267
+
268
+ error_logger = Ougai::Logger.new('./error.log')
269
+ logger.extend Ougai::Logger.broadcast(error_logger)
270
+
271
+ logger.level = Logger::INFO
272
+ logger.info('Hello!')
273
+
274
+ error_logger.level = Logger::ERROR
275
+ logger.error('Failed to do something.')
276
+
277
+ logger.level = Logger::WARN # error_logger level is also set WARN by propagation
278
+ logger.warn('Ignored something.')
279
+ ```
280
+
281
+ ##### STDOUT
282
+
283
+ ```json
284
+ {"name":"main","hostname":"mint","pid":24915,"level":30,"time":"2017-08-16T17:23:42.415+09:00","v":0,"msg":"Hello!"}
285
+ {"name":"main","hostname":"mint","pid":24915,"level":50,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Failed to do something."}
286
+ {"name":"main","hostname":"mint","pid":24915,"level":40,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Ignored something."}
287
+ ```
288
+
289
+ ##### error.log
290
+
291
+ ```json
292
+ {"name":"main","hostname":"mint","pid":24915,"level":50,"time":"2017-08-16T17:23:42.415+09:00","v":0,"msg":"Failed to do something."}
293
+ {"name":"main","hostname":"mint","pid":24915,"level":40,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Ignored something."}
294
+ ```
295
+
296
+
297
+ ## View pretty logs with node-bunyan or pino
298
+
299
+ Install [bunyan](https://github.com/trentm/node-bunyan) or [pino](https://github.com/pinojs/pino) via npm
300
+
301
+ ```
302
+ $ npm install -g bunyan
303
+ ```
304
+
305
+ Pipe a log file to command
306
+
307
+ ```
308
+ $ cat output.log | bunyan
309
+ [2016-10-16T22:26:48.835+09:00] INFO: main/14607 on mint: Info message!
310
+ [2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debugging (data_id=1, data_flag=true)
311
+ [2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debug!
312
+ custom_data: {
313
+ "id": 1,
314
+ "name": "something"
315
+ }
316
+ [2016-10-16T22:26:48.836+09:00] FATAL: main/14607 on mint: Unexpected!
317
+ main.rb:12:in `<main>'
318
+ [2016-10-16T22:26:48.836+09:00] ERROR: main/14607 on mint: Caught error (reason="z
319
+ main.rb:18:in `/'
320
+ main.rb:18:in `<main>'
321
+ ```
322
+
323
+ If you use *Ougai::Formatters::Pino*, you can use command [pino](https://github.com/pinojs/pino) as well as [bunyan](https://github.com/trentm/node-bunyan).
324
+
325
+ ## Use human Readable formatter for console
326
+
327
+ Add awesome_print to Gemfile and `bundle`
328
+
329
+ ```ruby
330
+ gem 'awesome_print'
331
+ ```
332
+
333
+ Set *Ougai::Formatters::Readable* instance to `formatter` accessor
334
+
335
+ ```ruby
336
+ require 'rubygems'
337
+ require 'ougai'
338
+
339
+ logger = Ougai::Logger.new(STDOUT)
340
+ logger.formatter = Ougai::Formatters::Readable.new
341
+ ```
342
+
343
+ ### Screen result example
344
+
345
+ ![Screen Shot](https://github.com/tilfin/ougai/blob/images/ougai_readable_format.png?raw=true)
346
+
347
+
348
+ ## How to use with famous products, services and libraries
349
+
350
+ - [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)
351
+ - [Customize Sidekiq logger](https://github.com/tilfin/ougai/wiki/Customize-Sidekiq-logger)
352
+ - [Forward logs to Fluentd](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Fluentd)
353
+ - [Forward logs to Logentries](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Logentries)
354
+ - [Use as ServerEngine logger](https://github.com/tilfin/ougai/wiki/Use-as-ServerEngine-logger)
355
+ - [Forward logs to Loggly](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Loggly)
356
+ - [Use as Rack logger](https://github.com/tilfin/ougai/wiki/Use-as-Rack-logger)
357
+
358
+ ## Custom formatters and integrations
359
+ - [Awesome Ougai](https://github.com/tilfin/ougai/wiki/Awesom-Ougai)
360
+
361
+ ## License
362
+
363
+ [MIT](LICENSE.txt)