slack_log_device 4.2.0 → 5.0.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
- SHA1:
3
- metadata.gz: 31f35ecd773a685a25208243fbbcb1e2b805215f
4
- data.tar.gz: 28b565110cf143e6feee787d7d6ef113466f71da
2
+ SHA256:
3
+ metadata.gz: b7b2d241f21d1b8ba8cfffcc91a953e49cdcc8749c4e5a928c28122bfd182727
4
+ data.tar.gz: 94d57be944548bcfc9ec35cd4c7fb15b3ca9d9d9c7f008cce786305229cb91bc
5
5
  SHA512:
6
- metadata.gz: 0d9adc9fd2299c95b90a454c7130081bd08f7b5908d5a620f5eaaee5ccac3c1b9ddb3ff7153c58c7ade3b01ee5319f3393a36830366d0514dea12c2187cee974
7
- data.tar.gz: 7237cd552536ed52d1c784575d1550d639e85d81ca948d1a1a063ad142f4ac7d69aa8a81acd30d9f80eb777b20382cc7937208e6681095359823a1d58208c0cb
6
+ metadata.gz: 40db4fc21132cf83a3d8a3bdf302ce2caecf21533e3a2e9e453eae3a9b0437518c6d76cab9357d6ea7b264fa534b42524e37081100f4d2bbfab670dc2eb46a36
7
+ data.tar.gz: c4e2605ca62508a47a1d1136cc65cc39973e1f36cd6317f0ea4b0f577b59e4d332dbc19f0415b1d9b0a59704144a155c0d10b75c70359c150ffccd988ac37e0c
data/README.mdown CHANGED
@@ -34,7 +34,10 @@ by default).
34
34
  - `channel`: The channel to post message on (webhook configured channel by
35
35
  default). It can be a channel (if starting with `#`) or a specific user (if
36
36
  starting with a `@`).
37
- - `flush_delay`: The delay in seconds to send buffered messages (1 by default).
37
+ - `disable_default_metadata`: `true` to disable default metadata (User,
38
+ Machine and PID). This is `false` (enabled) by default.
39
+ - `flush_delay`: The delay in seconds to send buffered messages (1 by
40
+ default).
38
41
  - `max_buffer_size`: The max messages count to flush them (10 messages by
39
42
  default).
40
43
  - `timeout`: The timeout in seconds to send message to slack (5 by default).
@@ -63,16 +66,25 @@ logger.formatter = SlackLogDevice.formatter { |message| message.reverse }
63
66
 
64
67
  ### Metadata
65
68
 
69
+ By default, formatter adds those metadata:
70
+
71
+ - `PID`: The current process id.
72
+ - `User`: The current user (`ENV['USER']`).
73
+ - `Machine`: The machine name (`hostname`).
74
+
66
75
  You can also add custom metadata to message sent to slack, here is how to do
67
76
  it:
68
77
 
69
78
  ```ruby
70
79
  logger.formatter = SlackLogDevice.formatter(extra_metadata: {
71
- 'User' => -> (options) { ENV['USER'] },
72
- 'Machine' => `uname -a`,
80
+ 'Exception class' => -> (options) { options[:exception].class.name },
81
+ 'System' => `uname -a`,
73
82
  })
74
83
  ```
75
84
 
85
+ As you can see, blocks (invoked with options contains `request` and
86
+ `exception`) are supported.
87
+
76
88
  ### Backtrace
77
89
 
78
90
  Exception backtrace is automatically stripped to `10` lines. You can change
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.0
1
+ 5.0.0
@@ -2,6 +2,7 @@ require 'active_support/core_ext/hash'
2
2
  require 'active_support/core_ext/string'
3
3
  require 'httparty'
4
4
  require 'logger'
5
+ require 'socket'
5
6
 
6
7
  class SlackLogDevice
7
8
 
@@ -7,9 +7,10 @@ class SlackLogDevice
7
7
  attr_reader :extra_metadata, :max_backtrace_lines
8
8
 
9
9
  def initialize(options = {}, &block)
10
- options.assert_valid_keys(:extra_metadata, :max_backtrace_lines)
10
+ options.assert_valid_keys(:disable_default_metadata, :extra_metadata, :max_backtrace_lines)
11
11
  self.extra_metadata = options.key?(:extra_metadata) ? options[:extra_metadata] : {}
12
12
  self.max_backtrace_lines = options.key?(:max_backtrace_lines) ? options[:max_backtrace_lines] : 10
13
+ @disable_default_metadata = options[:disable_default_metadata].present?
13
14
  @message_converter = block_given? ? Proc.new(&block) : -> (message) { message }
14
15
  end
15
16
 
@@ -31,6 +32,10 @@ class SlackLogDevice
31
32
  truncate(text)
32
33
  end
33
34
 
35
+ def disable_default_metadata?
36
+ @disable_default_metadata.present?
37
+ end
38
+
34
39
  private
35
40
 
36
41
  def append_exception_backtrace(text, exception)
@@ -58,16 +63,22 @@ class SlackLogDevice
58
63
  end
59
64
 
60
65
  def default_metadata(request)
61
- return {} if request.blank?
62
- metadata = {
66
+ metadata = {}
67
+ return metadata if disable_default_metadata?
68
+ metadata.merge!({
63
69
  'Method' => request.method,
64
70
  'URL' => request.url,
65
71
  'Remote address' => request.remote_addr,
66
72
  'User-Agent' => request.user_agent,
67
- }
73
+ }) if request.present?
74
+ metadata.merge!({
75
+ 'User' => ENV['USER'],
76
+ 'Machine' => Socket.gethostname,
77
+ 'PID' => Process.pid,
78
+ })
68
79
  metadata.keys.each do |key|
69
80
  value = metadata[key]
70
- metadata[key] = "`#{value.strip}`" if value.present?
81
+ metadata[key] = "`#{value.to_s.strip}`" if value.present?
71
82
  end
72
83
  metadata
73
84
  end
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.2.0
4
+ version: 5.0.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-09 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.5.1
147
+ rubygems_version: 2.7.3
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: LogDevice for Slack