ougai 1.0.0 → 1.1.0

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: d30c9475aab949b8119bbb1bb5b921b82cab591f
4
- data.tar.gz: 1a60805fd8a9602104c4f45180b54f1db48c5a81
3
+ metadata.gz: 54135d508028ceae123d4ac6554fdcfce52709c5
4
+ data.tar.gz: 9e7701c90d42b6db02d05d2c845687ac62bd60a5
5
5
  SHA512:
6
- metadata.gz: abb0ce860369b3ff1bf6f3f853e965dae781fd73cf341c954f2fd5f1d9316027850fe6c29eb339cf3b4d9e4abc870af1f39e27a9eb11845ac3532905ab89ed25
7
- data.tar.gz: 31bd2e3c9795548c6b47c4a874b0dee68fd98242037040601fc81f8806c2cdff5b3b005cbb708e83ddbe72c168551b67ad437f1dafa855d2f5db63b00942c502
6
+ metadata.gz: 4a52e06b9b082e80e7df479a073e390df104e5066ce434eb4c12edb8bbf56250c7ef46908cee56cb6130724da7671c3a4f86a52e297b5f983379cd18839b4f23
7
+ data.tar.gz: 3a84a43bbd5d6207b102794d210cc4dd9fdb74426dc3890663d12f6b40b8a326211c56d3510b76c88626481718782da5aff69692ee17b42de707f3f5bdb4d91a
@@ -3,12 +3,13 @@ require 'ougai/formatters/base'
3
3
  module Ougai
4
4
  module Formatters
5
5
  class Readable < Base
6
- attr_accessor :plain, :trace_indent
6
+ attr_accessor :plain, :trace_indent, :excluded_fields
7
7
 
8
8
  def initialize(opts = {})
9
9
  super(opts[:app_name], opts[:hostname])
10
10
  @trace_indent = opts[:trace_indent] || 4
11
11
  @plain = opts[:plain] || false
12
+ @excluded_fields = opts[:excluded_fields] || []
12
13
  load_awesome_print
13
14
  end
14
15
 
@@ -16,12 +17,10 @@ module Ougai
16
17
  msg = data.delete(:msg)
17
18
  level = @plain ? severity : colored_level(severity)
18
19
  strs = ["[#{time.iso8601(3)}] #{level}: #{msg}"]
19
- if data.key?(:err)
20
- err = data.delete(:err)
21
- err_str = " #{err[:name]} (#{err[:message]}):"
22
- err_str += "\n " + err[:stack] if err.key?(:stack)
20
+ if err_str = create_err_str(data)
23
21
  strs.push(err_str)
24
22
  end
23
+ @excluded_fields.each { |f| data.delete(f) }
25
24
  unless data.empty?
26
25
  strs.push(data.ai({ plain: @plain }))
27
26
  end
@@ -44,6 +43,14 @@ module Ougai
44
43
  "\e[#{color}m#{severity}\e[0m"
45
44
  end
46
45
 
46
+ def create_err_str(data)
47
+ return nil unless data.key?(:err)
48
+ err = data.delete(:err)
49
+ err_str = " #{err[:name]} (#{err[:message]}):"
50
+ err_str += "\n " + err[:stack] if err.key?(:stack)
51
+ err_str
52
+ end
53
+
47
54
  private
48
55
 
49
56
  def load_awesome_print
@@ -9,8 +9,8 @@ module Ougai
9
9
  super(*args)
10
10
  @default_message = 'No message'
11
11
  @exc_key = :err
12
- @formatter = create_formatter
13
12
  @with_fields = {}
13
+ @formatter = create_formatter
14
14
  end
15
15
 
16
16
  def debug(message = nil, ex = nil, data = nil, &block)
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -61,4 +61,18 @@ describe Ougai::Formatters::Readable do
61
61
  expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include("error1.rb\n error2.rb")
62
62
  end
63
63
  end
64
+
65
+ context 'when logger has excluded_fields' do
66
+ subject do
67
+ described_class.new(excluded_fields: [:status, :method]).call('DEBUG', Time.now, nil, data)
68
+ end
69
+
70
+ it 'includes valid strings' do
71
+ expect(subject).to include("\e[0;37mDEBUG\e[0m: Log Message!")
72
+ plain_subject = subject.gsub(/\e\[([;\d]+)?m/, '')
73
+ expect(plain_subject).to include(':path => "/"')
74
+ expect(plain_subject).not_to include(':status => 200')
75
+ expect(plain_subject).not_to include(':method => "GET"')
76
+ end
77
+ end
64
78
  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.0.0
4
+ version: 1.1.0
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-07-22 00:00:00.000000000 Z
11
+ date: 2017-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.5.1
101
+ rubygems_version: 2.6.11
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: JSON logger compatible with node-bunyan is capable of handling data easily.