ougai 1.5.6 → 1.5.7

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: b0be28a9823a80734981fe6333f87b5369e61094
4
- data.tar.gz: 4fee2e596d358d32409c86e46235539bfc796dee
3
+ metadata.gz: ceb8c682480975c5a3f5ab0da5f8336ad340d2f7
4
+ data.tar.gz: a23137a6d8297fb787a6b0c9b3ec50c2630d04d2
5
5
  SHA512:
6
- metadata.gz: 1845cb73f37a0a48406f66d24dc68dcc2f6d6f4a161feaae880ab20557baf7bac77d1032fcfe131e028cd9e6c866f52949e3bf2e74dfdea0e728799912b5d2ea
7
- data.tar.gz: ea9ac008a278ae1e879c5fdaf7080c9e2e0dbca1f781f4deade03c794eba36dd894d0bab6568c7a2d88681737a163cfa95b9801db7b5dbd566891071c8dbb170
6
+ metadata.gz: 41fd722562d4e09300b5048b7c74f540e4d54486f83e95fd722c16eb78e20334e3976e5441c63ae3d93c46508d5db81bcf06b867734b1d0b8cd6e4046e28d127
7
+ data.tar.gz: eedadc34fdae3207aceb6fb1aea85e3458e5d1fae44cb09da2117e8092289dcd89ab786ba0654c8bf0d5b607b08186ac21ce11b77e1dfb72f7d8d7ee1b78598f
data/README.md CHANGED
@@ -351,6 +351,7 @@ logger.formatter = Ougai::Formatters::Readable.new
351
351
  - [Forward logs to Logentries](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Logentries)
352
352
  - [Use as ServerEngine logger](https://github.com/tilfin/ougai/wiki/Use-as-ServerEngine-logger)
353
353
  - [Forward logs to Loggly](https://github.com/tilfin/ougai/wiki/Forward-logs-to-Loggly)
354
+ - [Use as Rack logger](https://github.com/tilfin/ougai/wiki/Use-as-Rack-logger)
354
355
 
355
356
  ## License
356
357
 
@@ -3,8 +3,13 @@ require 'socket'
3
3
 
4
4
  module Ougai
5
5
  module Formatters
6
+ # Base formatter
7
+ # @attr [Fixnum] trace_indent Specify exception backtrace indent (by default this is 2).
8
+ # @attr [Fixnum] trace_max_lines Keep exception backtrace lines (by default this is 100).
9
+ # @attr [Boolean] serialize_backtrace Whether exception should converts String (by default this is on).
6
10
  class Base < Logger::Formatter
7
11
  attr_accessor :trace_indent, :trace_max_lines
12
+ attr_accessor :serialize_backtrace
8
13
  attr_reader :app_name, :hostname
9
14
 
10
15
  def initialize(app_name = nil, hostname = nil)
@@ -12,6 +17,7 @@ module Ougai
12
17
  @hostname = hostname || Socket.gethostname.force_encoding('UTF-8')
13
18
  @trace_indent = 2
14
19
  @trace_max_lines = 100
20
+ @serialize_backtrace = true
15
21
  self.datetime_format = nil
16
22
  end
17
23
 
@@ -25,14 +31,15 @@ module Ougai
25
31
  message: ex.to_s
26
32
  }
27
33
  if ex.backtrace
28
- err[:stack] = serialize_trace(ex.backtrace)
34
+ bt = ex.backtrace.slice(0, @trace_max_lines)
35
+ err[:stack] = @serialize_backtrace ? serialize_trace(bt) : bt
29
36
  end
30
37
  err
31
38
  end
32
39
 
33
40
  def serialize_trace(trace)
34
41
  sp = "\n" + ' ' * @trace_indent
35
- trace.slice(0, @trace_max_lines).join(sp)
42
+ trace.join(sp)
36
43
  end
37
44
 
38
45
  private
@@ -14,6 +14,7 @@ module Ougai
14
14
  @trace_indent = opts[:trace_indent] || 4
15
15
  @plain = opts[:plain] || false
16
16
  @excluded_fields = opts[:excluded_fields] || []
17
+ @serialize_backtrace = true
17
18
  load_dependent
18
19
  end
19
20
 
@@ -28,6 +29,10 @@ module Ougai
28
29
  format_log_parts(dt, level, msg, err_str, data_str)
29
30
  end
30
31
 
32
+ def serialize_backtrace=(value)
33
+ raise RuntimeError, 'Not support serialize_backtrace'
34
+ end
35
+
31
36
  protected
32
37
 
33
38
  def format_log_parts(datetime, level, msg, err, data)
@@ -61,7 +66,7 @@ module Ougai
61
66
  return nil unless data.key?(:err)
62
67
  err = data.delete(:err)
63
68
  err_str = " #{err[:name]} (#{err[:message]}):"
64
- err_str += "\n " + err[:stack] if err.key?(:stack)
69
+ err_str += "\n" + (" " * @trace_indent) + err[:stack] if err.key?(:stack)
65
70
  err_str
66
71
  end
67
72
 
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = "1.5.6"
2
+ VERSION = "1.5.7"
3
3
  end
@@ -64,4 +64,35 @@ describe Ougai::Formatters::Base do
64
64
  expect(subject.hostname).to eq('myhost')
65
65
  end
66
66
  end
67
+
68
+ describe '#serialize_exc' do
69
+ let (:app_name) { 'myapp' }
70
+ let (:hostname) { 'myhost' }
71
+ let (:errmsg) { 'dummy error' }
72
+
73
+ it 'returning data with stack as String' do
74
+ begin
75
+ raise errmsg
76
+ rescue => e
77
+ result = subject.serialize_exc(e)
78
+ end
79
+ expect(result[:message]).to eq(errmsg)
80
+ expect(result[:stack]).to be_instance_of(String)
81
+ end
82
+
83
+ context 'not serialize backtrace' do
84
+ it 'returning data with stack as Array' do
85
+ subject.serialize_backtrace = false
86
+ subject.trace_max_lines = 6
87
+ begin
88
+ raise errmsg
89
+ rescue => e
90
+ result = subject.serialize_exc(e)
91
+ end
92
+ expect(result[:message]).to eq(errmsg)
93
+ expect(result[:stack]).to be_instance_of(Array)
94
+ expect(result[:stack].size).to eq(6)
95
+ end
96
+ end
97
+ end
67
98
  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.5.6
4
+ version: 1.5.7
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-11-10 00:00:00.000000000 Z
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,17 +103,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.6.11
106
+ rubygems_version: 2.6.13
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: JSON logger compatible with node-bunyan is capable of handling structured
110
110
  data easily.
111
111
  test_files:
112
- - spec/child_logger_spec.rb
113
112
  - spec/formatters/base_spec.rb
114
113
  - spec/formatters/bunyan_spec.rb
115
114
  - spec/formatters/readable_spec.rb
116
- - spec/logger_spec.rb
115
+ - spec/child_logger_spec.rb
117
116
  - spec/logging_spec.rb
117
+ - spec/logger_spec.rb
118
118
  - spec/ougai_spec.rb
119
119
  - spec/spec_helper.rb