ougai 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +49 -0
- data/README.md +7 -5
- data/Rakefile +11 -0
- data/lib/ougai.rb +2 -0
- data/lib/ougai/formatters/base.rb +21 -4
- data/lib/ougai/formatters/bunyan.rb +18 -25
- data/lib/ougai/formatters/for_json.rb +23 -0
- data/lib/ougai/formatters/pino.rb +73 -0
- data/lib/ougai/formatters/readable.rb +17 -8
- data/lib/ougai/version.rb +1 -1
- data/spec/formatters/pino_spec.rb +142 -0
- metadata +8 -5
- data/.gitignore +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a3a13441e1374f9f227801a4fa3b01992e05c7f
|
4
|
+
data.tar.gz: 0e2a39093027b4a0ad7c82b2626460ae07225e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62426a676338318a26d1c37e72bd9f5221d8f980fc810bb939ac6a19631b77c9a44193f43dc21e31f362e62194f3ee99e4f2fc15e54c9781336beaea571f7802
|
7
|
+
data.tar.gz: 2b027dbbc7bbeff72e7069e0cdf899609a3ca45ec0e0c241349af5025c7b6f2e4e34b93a1401a3edd1677bfcd6c69f1aadc63bfca78c8e4a87090e6f2ab6137f
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ougai (1.6.3)
|
5
|
+
oj (~> 3.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
awesome_print (1.8.0)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.5)
|
13
|
+
json (2.1.0)
|
14
|
+
oj (3.4.0)
|
15
|
+
rake (10.5.0)
|
16
|
+
rspec (3.5.0)
|
17
|
+
rspec-core (~> 3.5.0)
|
18
|
+
rspec-expectations (~> 3.5.0)
|
19
|
+
rspec-mocks (~> 3.5.0)
|
20
|
+
rspec-core (3.5.4)
|
21
|
+
rspec-support (~> 3.5.0)
|
22
|
+
rspec-expectations (3.5.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.5.0)
|
25
|
+
rspec-mocks (3.5.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.5.0)
|
28
|
+
rspec-support (3.5.0)
|
29
|
+
simplecov (0.14.1)
|
30
|
+
docile (~> 1.1.0)
|
31
|
+
json (>= 1.8, < 3)
|
32
|
+
simplecov-html (~> 0.10.0)
|
33
|
+
simplecov-html (0.10.1)
|
34
|
+
yard (0.9.12)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
awesome_print
|
41
|
+
bundler (~> 1.11)
|
42
|
+
ougai!
|
43
|
+
rake (~> 10.0)
|
44
|
+
rspec (~> 3.0)
|
45
|
+
simplecov
|
46
|
+
yard
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.16.0
|
data/README.md
CHANGED
@@ -2,12 +2,13 @@ Ougai
|
|
2
2
|
=====
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/ougai)
|
5
|
+
[](http://www.rubydoc.info/gems/ougai/1.6.3/)
|
5
6
|
[](https://travis-ci.org/tilfin/ougai)
|
6
7
|
[](https://codeclimate.com/github/tilfin/ougai)
|
7
8
|
[](https://codeclimate.com/github/tilfin/ougai/coverage)
|
8
9
|
|
9
10
|
A structured logging system is capable of handling a message, structured data or an exception easily.
|
10
|
-
It has JSON
|
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
|
11
12
|
human readable formatter with [Awesome Print](https://github.com/awesome-print/awesome_print) for console.
|
12
13
|
|
13
14
|
## Installation
|
@@ -293,18 +294,18 @@ logger.warn('Ignored something.')
|
|
293
294
|
```
|
294
295
|
|
295
296
|
|
296
|
-
## View logs with node-bunyan
|
297
|
+
## View pretty logs with node-bunyan or pino
|
297
298
|
|
298
|
-
Install [bunyan](https://github.com/trentm/node-bunyan) via npm
|
299
|
+
Install [bunyan](https://github.com/trentm/node-bunyan) or [pino](https://github.com/pinojs/pino) via npm
|
299
300
|
|
300
301
|
```
|
301
302
|
$ npm install -g bunyan
|
302
303
|
```
|
303
304
|
|
304
|
-
|
305
|
+
Pipe a log file to command
|
305
306
|
|
306
307
|
```
|
307
|
-
$
|
308
|
+
$ cat output.log | bunyan
|
308
309
|
[2016-10-16T22:26:48.835+09:00] INFO: main/14607 on mint: Info message!
|
309
310
|
[2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debugging (data_id=1, data_flag=true)
|
310
311
|
[2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debug!
|
@@ -319,6 +320,7 @@ $ bunyan output.log
|
|
319
320
|
main.rb:18:in `<main>'
|
320
321
|
```
|
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).
|
322
324
|
|
323
325
|
## Use human Readable formatter for console
|
324
326
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
+
require 'yard'
|
4
|
+
require 'yard/rake/yardoc_task'
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new(:spec)
|
5
7
|
|
6
8
|
task :default => :spec
|
9
|
+
|
10
|
+
FILES = ['lib/**/*.rb']
|
11
|
+
OPTIONS = ['--debug', '--verbose']
|
12
|
+
|
13
|
+
YARD::Rake::YardocTask.new do |t|
|
14
|
+
t.files = FILES
|
15
|
+
t.options = []
|
16
|
+
t.options << OPTIONS if $trace
|
17
|
+
end
|
data/lib/ougai.rb
CHANGED
@@ -2,7 +2,9 @@ require 'logger'
|
|
2
2
|
require 'ougai/version'
|
3
3
|
require 'ougai/logging'
|
4
4
|
require 'ougai/formatters/base'
|
5
|
+
require 'ougai/formatters/for_json'
|
5
6
|
require 'ougai/formatters/bunyan'
|
6
7
|
require 'ougai/formatters/readable'
|
8
|
+
require 'ougai/formatters/pino'
|
7
9
|
require 'ougai/child_logger'
|
8
10
|
require 'ougai/logger'
|
@@ -13,12 +13,19 @@ module Ougai
|
|
13
13
|
attr_accessor :serialize_backtrace
|
14
14
|
attr_reader :app_name, :hostname
|
15
15
|
|
16
|
-
|
16
|
+
# Intialize a formatter
|
17
|
+
# @param [String] app_name application name
|
18
|
+
# @param [String] hostname hostname
|
19
|
+
# @param [Hash] opts the initial values of attributes
|
20
|
+
# @option opts [String] :trace_indent (2) the value of trace_indent attribute
|
21
|
+
# @option opts [String] :trace_max_lines (100) the value of trace_max_lines attribute
|
22
|
+
# @option opts [String] :serialize_backtrace (true) the value of serialize_backtrace attribute
|
23
|
+
def initialize(app_name = nil, hostname = nil, opts = {})
|
17
24
|
@app_name = app_name || File.basename($0, ".rb")
|
18
25
|
@hostname = hostname || Socket.gethostname.force_encoding('UTF-8')
|
19
|
-
@trace_indent = 2
|
20
|
-
@trace_max_lines = 100
|
21
|
-
@serialize_backtrace = true
|
26
|
+
@trace_indent = opts.fetch(:trace_indent, 2)
|
27
|
+
@trace_max_lines = opts.fetch(:trace_max_lines, 100)
|
28
|
+
@serialize_backtrace = opts.fetch(:serialize_backtrace, true)
|
22
29
|
self.datetime_format = nil
|
23
30
|
end
|
24
31
|
|
@@ -63,6 +70,16 @@ module Ougai
|
|
63
70
|
f << (t.utc? ? 'Z' : '%:z')
|
64
71
|
f.freeze
|
65
72
|
end
|
73
|
+
|
74
|
+
def self.parse_new_params(args)
|
75
|
+
idx = args.index {|i| i.is_a?(Hash) }
|
76
|
+
return args if idx == 2
|
77
|
+
opts = args[idx]
|
78
|
+
app_name = opts.delete(:app_name)
|
79
|
+
hostname = opts.delete(:hostname)
|
80
|
+
app_name ||= args[0] if idx > 0
|
81
|
+
[app_name, hostname, opts]
|
82
|
+
end
|
66
83
|
end
|
67
84
|
end
|
68
85
|
end
|
@@ -4,15 +4,27 @@ require 'oj'
|
|
4
4
|
module Ougai
|
5
5
|
module Formatters
|
6
6
|
# A JSON formatter compatible with node-bunyan
|
7
|
-
# @attr [Boolean] jsonize Whether log should converts JSON
|
8
|
-
# @attr [Boolean] with_newline Whether tailing NL should be appended
|
7
|
+
# @attr [Boolean] jsonize Whether log should converts JSON
|
8
|
+
# @attr [Boolean] with_newline Whether tailing NL should be appended
|
9
9
|
class Bunyan < Base
|
10
|
+
include ForJson
|
11
|
+
|
10
12
|
attr_accessor :jsonize, :with_newline
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# Intialize a formatter
|
15
|
+
# @param [String] app_name application name (execution program name if nil)
|
16
|
+
# @param [String] hostname hostname (hostname if nil)
|
17
|
+
# @param [Hash] opts the initial values of attributes
|
18
|
+
# @option opts [String] :trace_indent (2) the value of trace_indent attribute
|
19
|
+
# @option opts [String] :trace_max_lines (100) the value of trace_max_lines attribute
|
20
|
+
# @option opts [String] :serialize_backtrace (true) the value of serialize_backtrace attribute
|
21
|
+
# @option opts [String] :jsonize (true) the value of jsonize attribute
|
22
|
+
# @option opts [String] :with_newline (true) the value of with_newline attribute
|
23
|
+
def initialize(app_name = nil, hostname = nil, opts = {})
|
24
|
+
aname, hname, opts = Base.parse_new_params([app_name, hostname, opts])
|
25
|
+
super(aname, hname, opts)
|
26
|
+
@jsonize = opts.fetch(:jsonize, true)
|
27
|
+
@with_newline = opts.fetch(:with_newline, true)
|
16
28
|
end
|
17
29
|
|
18
30
|
def _call(severity, time, progname, data)
|
@@ -26,25 +38,6 @@ module Ougai
|
|
26
38
|
}.merge(data))
|
27
39
|
end
|
28
40
|
|
29
|
-
def to_level(severity)
|
30
|
-
case severity
|
31
|
-
when 'TRACE'
|
32
|
-
10
|
33
|
-
when 'DEBUG'
|
34
|
-
20
|
35
|
-
when 'INFO'
|
36
|
-
30
|
37
|
-
when 'WARN'
|
38
|
-
40
|
39
|
-
when 'ERROR'
|
40
|
-
50
|
41
|
-
when 'FATAL'
|
42
|
-
60
|
43
|
-
else
|
44
|
-
70
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
41
|
private
|
49
42
|
|
50
43
|
OJ_OPTIONS = { mode: :custom, time_format: :xmlschema,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ougai
|
2
|
+
# The features for JSON
|
3
|
+
module Formatters::ForJson
|
4
|
+
def to_level(severity)
|
5
|
+
case severity
|
6
|
+
when 'TRACE'
|
7
|
+
10
|
8
|
+
when 'DEBUG'
|
9
|
+
20
|
10
|
+
when 'INFO'
|
11
|
+
30
|
12
|
+
when 'WARN'
|
13
|
+
40
|
14
|
+
when 'ERROR'
|
15
|
+
50
|
16
|
+
when 'FATAL'
|
17
|
+
60
|
18
|
+
else
|
19
|
+
70
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'ougai/formatters/base'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
module Ougai
|
5
|
+
module Formatters
|
6
|
+
# A JSON formatter compatible with pino
|
7
|
+
# @attr [Boolean] jsonize Whether log should converts JSON
|
8
|
+
# @attr [Boolean] with_newline Whether tailing NL should be appended
|
9
|
+
class Pino < Base
|
10
|
+
include ForJson
|
11
|
+
|
12
|
+
attr_accessor :jsonize, :with_newline
|
13
|
+
|
14
|
+
# Intialize a formatter
|
15
|
+
# @param [String] app_name application name (execution program name if nil)
|
16
|
+
# @param [String] hostname hostname (hostname if nil)
|
17
|
+
# @param [Hash] opts the initial values of attributes
|
18
|
+
# @option opts [String] :trace_indent (4) the value of trace_indent attribute
|
19
|
+
# @option opts [String] :trace_max_lines (100) the value of trace_max_lines attribute
|
20
|
+
# @option opts [String] :serialize_backtrace (true) the value of serialize_backtrace attribute
|
21
|
+
# @option opts [String] :jsonize (true) the value of jsonize attribute
|
22
|
+
# @option opts [String] :with_newline (true) the value of with_newline attribute
|
23
|
+
def initialize(app_name = nil, hostname = nil, opts = {})
|
24
|
+
aname, hname, opts = Base.parse_new_params([app_name, hostname, opts])
|
25
|
+
super(aname, hname, opts)
|
26
|
+
@jsonize = opts.fetch(:jsonize, true)
|
27
|
+
@with_newline = opts.fetch(:with_newline, true)
|
28
|
+
@trace_indent = opts.fetch(:trace_indent, 4)
|
29
|
+
@serialize_backtrace = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def datetime_format=(val)
|
33
|
+
raise NotImplementedError, 'Not support datetime_format attribute' unless val.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def _call(severity, time, progname, data)
|
37
|
+
flat_err(data)
|
38
|
+
dump({
|
39
|
+
name: progname || @app_name,
|
40
|
+
hostname: @hostname,
|
41
|
+
pid: $$,
|
42
|
+
level: to_level(severity),
|
43
|
+
time: time,
|
44
|
+
v: 1
|
45
|
+
}.merge(data))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def flat_err(data)
|
51
|
+
return unless data.key?(:err)
|
52
|
+
err = data.delete(:err)
|
53
|
+
msg = err[:message]
|
54
|
+
data[:type] ||= 'Error'
|
55
|
+
data[:msg] ||= msg
|
56
|
+
stack = "#{err[:name]}: #{msg}"
|
57
|
+
stack += "\n" + (" " * @trace_indent) + err[:stack] if err.key?(:stack)
|
58
|
+
data[:stack] ||= stack
|
59
|
+
end
|
60
|
+
|
61
|
+
OJ_OPTIONS = { mode: :custom, time_format: :xmlschema,
|
62
|
+
use_as_json: true, use_to_hash: true, use_to_json: true }
|
63
|
+
|
64
|
+
def dump(data)
|
65
|
+
return data unless @jsonize
|
66
|
+
data[:time] = data[:time].to_i * 1000
|
67
|
+
str = Oj.dump(data, OJ_OPTIONS)
|
68
|
+
str << "\n" if @with_newline
|
69
|
+
str
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -3,16 +3,25 @@ require 'ougai/formatters/base'
|
|
3
3
|
module Ougai
|
4
4
|
module Formatters
|
5
5
|
# A human readble formatter with awesome_print
|
6
|
-
# @attr [Boolean] plain Whether log should be plain not colorized
|
7
|
-
# @attr [
|
8
|
-
# @attr [Array<String, Symbol>] excluded_fields The fields excluded from all logs.
|
6
|
+
# @attr [Boolean] plain Whether log should be plain not colorized.
|
7
|
+
# @attr [Array<String, Symbol>] excluded_fields The fields excluded from all logs
|
9
8
|
class Readable < Base
|
10
|
-
attr_accessor :plain, :
|
9
|
+
attr_accessor :plain, :excluded_fields
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# Intialize a formatter
|
12
|
+
# @param [String] app_name application name (execution program name if nil)
|
13
|
+
# @param [String] hostname hostname (hostname if nil)
|
14
|
+
# @param [Hash] opts the initial values of attributes
|
15
|
+
# @option opts [String] :trace_indent (4) the value of trace_indent attribute
|
16
|
+
# @option opts [String] :trace_max_lines (100) the value of trace_max_lines attribute
|
17
|
+
# @option opts [String] :serialize_backtrace (true) the value of serialize_backtrace attribute
|
18
|
+
# @option opts [String] :plain (false) the value of plain attribute
|
19
|
+
# @option opts [String] :excluded_fields ([]) the value of excluded_fields attribute
|
20
|
+
def initialize(app_name = nil, hostname = nil, opts = {})
|
21
|
+
aname, hname, opts = Base.parse_new_params([app_name, hostname, opts])
|
22
|
+
super(aname, hname, opts)
|
23
|
+
@trace_indent = opts.fetch(:trace_indent, 4)
|
24
|
+
@plain = opts.fetch(:plain, false)
|
16
25
|
@excluded_fields = opts[:excluded_fields] || []
|
17
26
|
@serialize_backtrace = true
|
18
27
|
load_dependent
|
data/lib/ougai/version.rb
CHANGED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ougai::Formatters::Pino do
|
4
|
+
let(:data) do
|
5
|
+
{
|
6
|
+
msg: 'Log Message!',
|
7
|
+
status: 200,
|
8
|
+
method: 'GET',
|
9
|
+
path: '/'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:err) do
|
14
|
+
{
|
15
|
+
name: 'DummyError',
|
16
|
+
message: 'it is dummy.',
|
17
|
+
stack: "error1.rb\n error2.rb"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:formatter) { described_class.new }
|
22
|
+
|
23
|
+
context '#initialize' do
|
24
|
+
let(:appname) { 'dummy app name' }
|
25
|
+
|
26
|
+
it 'suceeds with arguments' do
|
27
|
+
fmt = described_class.new(appname)
|
28
|
+
expect(fmt.app_name).to eq(appname)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'jsonize is true and with_newline is true' do
|
33
|
+
subject { formatter.call('DEBUG', Time.now, nil, data) }
|
34
|
+
|
35
|
+
it 'includes valid strings' do
|
36
|
+
expect(subject).to end_with("\n")
|
37
|
+
result = JSON.parse(subject.chomp, symbolize_names: true)
|
38
|
+
expect(result).to include(data.merge(level: 20))
|
39
|
+
expect(result[:time]).to be > 1518710101026
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'jsonize is false' do
|
44
|
+
before do
|
45
|
+
formatter.jsonize = false
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when severity is TRACE' do
|
49
|
+
subject { formatter.call('TRACE', Time.now, nil, data) }
|
50
|
+
|
51
|
+
it 'includes valid hash' do
|
52
|
+
expect(subject).to include(data.merge(level: 10))
|
53
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when severity is DEBUG' do
|
58
|
+
subject { formatter.call('DEBUG', Time.now, nil, data) }
|
59
|
+
|
60
|
+
it 'includes valid hash' do
|
61
|
+
expect(subject).to include(data.merge(level: 20))
|
62
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when severity is INFO' do
|
67
|
+
subject { formatter.call('INFO', Time.now, nil, data) }
|
68
|
+
|
69
|
+
it 'includes valid hash' do
|
70
|
+
expect(subject).to include(data.merge(level: 30))
|
71
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when severity is WARN' do
|
76
|
+
subject { formatter.call('WARN', Time.now, nil, data) }
|
77
|
+
|
78
|
+
it 'includes valid hash' do
|
79
|
+
expect(subject).to include(data.merge(level: 40))
|
80
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when severity is ERROR' do
|
85
|
+
subject {
|
86
|
+
data.delete(:msg)
|
87
|
+
formatter.call('ERROR', Time.now, nil, data.merge({ err: err }))
|
88
|
+
}
|
89
|
+
|
90
|
+
it 'includes valid hash' do
|
91
|
+
expect(subject).to include({
|
92
|
+
level: 50, type: 'Error',
|
93
|
+
msg: 'it is dummy.',
|
94
|
+
stack: "DummyError: it is dummy.\n error1.rb\n error2.rb"
|
95
|
+
})
|
96
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when severity is FATAL' do
|
101
|
+
subject { formatter.call('FATAL', Time.now, nil, { msg: 'TheEnd', err: err }) }
|
102
|
+
|
103
|
+
it 'includes valid hash' do
|
104
|
+
expect(subject).to include({
|
105
|
+
level: 60, type: 'Error',
|
106
|
+
msg: 'TheEnd',
|
107
|
+
stack: "DummyError: it is dummy.\n error1.rb\n error2.rb"
|
108
|
+
})
|
109
|
+
expect(subject[:time]).to be_an_instance_of(Time)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when severity is UNKNOWN' do
|
114
|
+
subject { formatter.call('ANY', Time.now, nil, { msg: 'unknown msg' }) }
|
115
|
+
|
116
|
+
it 'includes valid hash' do
|
117
|
+
expect(subject).to include(level: 70, msg: 'unknown msg')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'with_newline is false' do
|
123
|
+
before do
|
124
|
+
formatter.with_newline = false
|
125
|
+
end
|
126
|
+
|
127
|
+
subject { formatter.call('INFO', Time.now, nil, data) }
|
128
|
+
|
129
|
+
it 'includes valid strings' do
|
130
|
+
expect(subject).not_to end_with("\n")
|
131
|
+
result = JSON.parse(subject, symbolize_names: true)
|
132
|
+
expect(result).to include(data.merge(level: 30))
|
133
|
+
expect(result[:time]).to be > 1518710101026
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#datetime_format' do
|
138
|
+
it 'is not supported' do
|
139
|
+
expect{ formatter.datetime_format = '%I:%M:%S %p' }.to raise_error(NotImplementedError)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
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.6.
|
4
|
+
version: 1.6.3
|
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-
|
11
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -68,14 +68,13 @@ dependencies:
|
|
68
68
|
version: '3.0'
|
69
69
|
description: |2
|
70
70
|
A structured logging system is capable of handling a message, custom data or an exception easily.
|
71
|
-
It has JSON
|
71
|
+
It has JSON formatters compatible with Bunyan or pino for Node.js and human readable formatter with Awesome Print for console.
|
72
72
|
email:
|
73
73
|
- toshi@tilfin.com
|
74
74
|
executables: []
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- ".gitignore"
|
79
78
|
- Gemfile
|
80
79
|
- Gemfile.lock
|
81
80
|
- LICENSE.txt
|
@@ -85,6 +84,8 @@ files:
|
|
85
84
|
- lib/ougai/child_logger.rb
|
86
85
|
- lib/ougai/formatters/base.rb
|
87
86
|
- lib/ougai/formatters/bunyan.rb
|
87
|
+
- lib/ougai/formatters/for_json.rb
|
88
|
+
- lib/ougai/formatters/pino.rb
|
88
89
|
- lib/ougai/formatters/readable.rb
|
89
90
|
- lib/ougai/logger.rb
|
90
91
|
- lib/ougai/logging.rb
|
@@ -92,6 +93,7 @@ files:
|
|
92
93
|
- spec/child_logger_spec.rb
|
93
94
|
- spec/formatters/base_spec.rb
|
94
95
|
- spec/formatters/bunyan_spec.rb
|
96
|
+
- spec/formatters/pino_spec.rb
|
95
97
|
- spec/formatters/readable_spec.rb
|
96
98
|
- spec/logger_spec.rb
|
97
99
|
- spec/logging_spec.rb
|
@@ -120,9 +122,10 @@ rubyforge_project:
|
|
120
122
|
rubygems_version: 2.6.13
|
121
123
|
signing_key:
|
122
124
|
specification_version: 4
|
123
|
-
summary: JSON logger compatible with node-bunyan is capable of handling structured
|
125
|
+
summary: JSON logger compatible with node-bunyan or pino is capable of handling structured
|
124
126
|
data easily.
|
125
127
|
test_files:
|
128
|
+
- spec/formatters/pino_spec.rb
|
126
129
|
- spec/formatters/base_spec.rb
|
127
130
|
- spec/formatters/bunyan_spec.rb
|
128
131
|
- spec/formatters/readable_spec.rb
|