slack_log_device 4.1.0 → 4.2.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: a08add8ca43ec8b2845e209f84db5451c80b05f3
4
- data.tar.gz: 7d9b8604965d71003b13035b4760c38314c58420
3
+ metadata.gz: 31f35ecd773a685a25208243fbbcb1e2b805215f
4
+ data.tar.gz: 28b565110cf143e6feee787d7d6ef113466f71da
5
5
  SHA512:
6
- metadata.gz: 05903e2015b349a16066c6f9aa4f5413f09d53573931f51b9b6efa5ed6108be2816ced145a668246223e6a5a7cd314fc5a04d178d40aee24dbf8aab06dcfcce5
7
- data.tar.gz: 49374c1e5993469d1a1c2e7f80a0ec2d8bfb5b443babb7b2e6768ddf36152e8618a759cfc73b15c75eaeb99cdded92aa95ce3383791a546390658304f3f2c66d
6
+ metadata.gz: 0d9adc9fd2299c95b90a454c7130081bd08f7b5908d5a620f5eaaee5ccac3c1b9ddb3ff7153c58c7ade3b01ee5319f3393a36830366d0514dea12c2187cee974
7
+ data.tar.gz: 7237cd552536ed52d1c784575d1550d639e85d81ca948d1a1a063ad142f4ac7d69aa8a81acd30d9f80eb777b20382cc7937208e6681095359823a1d58208c0cb
data/README.mdown CHANGED
@@ -43,6 +43,8 @@ default).
43
43
 
44
44
  ## Formatter
45
45
 
46
+ ### Usage
47
+
46
48
  `slack_log_device` provides a log formatter to have a pretty output for slack.
47
49
  It can be configured like this:
48
50
 
@@ -50,6 +52,8 @@ It can be configured like this:
50
52
  logger.formatter = SlackLogDevice.formatter
51
53
  ```
52
54
 
55
+ ### Converting message
56
+
53
57
  `SlackLogDevice.formatter` method also accepts block to transform logged
54
58
  message, example:
55
59
 
@@ -57,6 +61,8 @@ message, example:
57
61
  logger.formatter = SlackLogDevice.formatter { |message| message.reverse }
58
62
  ```
59
63
 
64
+ ### Metadata
65
+
60
66
  You can also add custom metadata to message sent to slack, here is how to do
61
67
  it:
62
68
 
@@ -67,6 +73,20 @@ logger.formatter = SlackLogDevice.formatter(extra_metadata: {
67
73
  })
68
74
  ```
69
75
 
76
+ ### Backtrace
77
+
78
+ Exception backtrace is automatically stripped to `10` lines. You can change
79
+ this behavior via `:max_backtrace_lines`:
80
+
81
+ ```ruby
82
+ logger.formatter = SlackLogDevice.formatter(max_backtrace_lines: 50)
83
+ ```
84
+
85
+ - A value of `0` will not print backtrace.
86
+ - A value of `-1` will not strip backtrace.
87
+
88
+ ### Rails metadata
89
+
70
90
  If you use [Ruby on Rails](http://rubyonrails.org/), you will get some
71
91
  metadata like current HTTP method, URL, remote address and User-Agent (see
72
92
  Rails configuration section).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.1.0
1
+ 4.2.0
@@ -8,8 +8,8 @@ class SlackLogDevice
8
8
  attr_reader :channel, :flush_delay, :max_buffer_size, :timeout, :username, :webhook_url
9
9
 
10
10
  def self.enable_rails_logging!
11
- require 'slack_log_device/debug_exceptions'
12
- require 'slack_log_device/set_request_in_thread'
11
+ require "#{__dir__}/slack_log_device/debug_exceptions"
12
+ require "#{__dir__}/slack_log_device/set_request_in_thread"
13
13
  ActionDispatch::DebugExceptions.prepend(SlackLogDevice::DebugExceptions)
14
14
  Rails.application.config.middleware.insert_before(Rails::Rack::Logger, SlackLogDevice::SetRequestInThread)
15
15
  true
@@ -123,4 +123,4 @@ class SlackLogDevice
123
123
 
124
124
  end
125
125
 
126
- require 'slack_log_device/formatter'
126
+ require "#{__dir__}/slack_log_device/formatter"
@@ -4,11 +4,12 @@ class SlackLogDevice
4
4
 
5
5
  MAX_MESSAGE_LENGTH = 4000
6
6
 
7
- attr_reader :extra_metadata
7
+ attr_reader :extra_metadata, :max_backtrace_lines
8
8
 
9
9
  def initialize(options = {}, &block)
10
- options.assert_valid_keys(:extra_metadata)
11
- @extra_metadata = options.key?(:extra_metadata) ? options[:extra_metadata] : {}
10
+ options.assert_valid_keys(:extra_metadata, :max_backtrace_lines)
11
+ self.extra_metadata = options.key?(:extra_metadata) ? options[:extra_metadata] : {}
12
+ self.max_backtrace_lines = options.key?(:max_backtrace_lines) ? options[:max_backtrace_lines] : 10
12
13
  @message_converter = block_given? ? Proc.new(&block) : -> (message) { message }
13
14
  end
14
15
 
@@ -71,10 +72,21 @@ class SlackLogDevice
71
72
  metadata
72
73
  end
73
74
 
75
+ def extra_metadata=(value)
76
+ @extra_metadata = value.presence || {}
77
+ end
78
+
74
79
  def format_backtrace(exception, size_available)
75
- backtrace = exception.backtrace.try(:join, "\n")
76
- return nil if backtrace.blank? || size_available < 7
77
- "```#{truncate(backtrace, size_available - 6)}```"
80
+ return nil if max_backtrace_lines == 0 || size_available < 7
81
+ backtrace = (exception.backtrace || []).select(&:present?).compact
82
+ return nil if backtrace.empty?
83
+ if max_backtrace_lines < 0
84
+ text = backtrace.join("\n")
85
+ else
86
+ text = backtrace[0, max_backtrace_lines].join("\n")
87
+ text << "\n..." if backtrace.size > max_backtrace_lines
88
+ end
89
+ "```#{truncate(text, size_available - 6)}```"
78
90
  end
79
91
 
80
92
  def format_metadata(message, size_available)
@@ -91,6 +103,12 @@ class SlackLogDevice
91
103
  truncate(text, size_available)
92
104
  end
93
105
 
106
+ def max_backtrace_lines=(value)
107
+ length = Integer(value) rescue nil
108
+ raise ArgumentError.new("Invalid max backtrace lines: #{value.inspect}") if length.nil? || length < -1
109
+ @max_backtrace_lines = length
110
+ end
111
+
94
112
  def truncate(message, max_length = MAX_MESSAGE_LENGTH)
95
113
  message = message.strip
96
114
  return message if message.size <= max_length
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_log_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport