semlogr-sinks-seq 0.1.0 → 0.1.1
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 +5 -5
- data/CHANGELOG.md +4 -11
- data/LICENSE.md +21 -0
- data/lib/semlogr/sinks/seq/clef_formatter.rb +45 -0
- data/lib/semlogr/sinks/seq/sink.rb +25 -25
- data/lib/semlogr/sinks/seq/version.rb +1 -1
- data/semlogr-sinks-seq.gemspec +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6948bb4d0f7e5e84c57a76c73337f619962ea85
|
4
|
+
data.tar.gz: 9bfb3372a548cff950d8e6bace8da7250ca48967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb061971f2c955541f9a79891567f4fbc24a6a7ca79b3f75d0c415b0d6e9b48a5f9a2dc2350f668a6335ec6b28cd7a2dccda8e50faf34d2c9b4c05967400164
|
7
|
+
data.tar.gz: e9355726bc151cd433eca847bcfd89e812dc44a0aac5d2cb7d422b277189eeb93cee79a4ac2920f7a015476755a1a12e7072479f68b45e0ae7e740ba8728c794
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
### 0.
|
4
|
-
|
5
|
-
- Use new semlogr component registry
|
6
|
-
|
7
|
-
### 0.1.3
|
8
|
-
|
9
|
-
- Rubocop update (nothing useful)
|
10
|
-
|
11
|
-
### 0.1.2
|
3
|
+
### 0.1.1
|
12
4
|
|
13
|
-
-
|
5
|
+
- Add clef formatter instead of tacking onto existing JSON formatter
|
6
|
+
- Adding support to flush buffer on application exit so that we don't lose messages
|
14
7
|
|
15
|
-
### 0.1.
|
8
|
+
### 0.1.0
|
16
9
|
|
17
10
|
- Initial release
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Semlogr
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Semlogr
|
2
|
+
module Sinks
|
3
|
+
module Seq
|
4
|
+
class ClefFormatter
|
5
|
+
def initialize(opts = {})
|
6
|
+
default_opts = {
|
7
|
+
mode: :custom,
|
8
|
+
time_format: :ruby,
|
9
|
+
use_to_json: true
|
10
|
+
}
|
11
|
+
|
12
|
+
@opts = default_opts.merge(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def format(log_event)
|
16
|
+
event = {
|
17
|
+
'@t' => log_event.timestamp.iso8601(3),
|
18
|
+
'@l' => log_event.severity.to_s,
|
19
|
+
'@mt' => log_event.template.text
|
20
|
+
}
|
21
|
+
|
22
|
+
add_error(event, log_event.error)
|
23
|
+
add_properties(event, log_event.properties)
|
24
|
+
|
25
|
+
event_json = Oj.dump(event, @opts)
|
26
|
+
"#{event_json}\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def add_error(event, error)
|
32
|
+
return unless error
|
33
|
+
event['@x'] = "#{error[:type]}: #{error[:message]}"
|
34
|
+
|
35
|
+
return unless error[:backtrace] && error[:backtrace].any?
|
36
|
+
event['@x'] += "\n\s\s#{error[:backtrace].join("\n\s\s")}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_properties(event, properties)
|
40
|
+
event.merge!(properties) { |_, old, _| old }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'timeout'
|
1
2
|
require 'stud/buffer'
|
2
|
-
require 'semlogr/
|
3
|
+
require 'semlogr/sinks/seq/clef_formatter'
|
3
4
|
require 'semlogr/sinks/seq/seq_api'
|
4
5
|
|
5
6
|
module Semlogr
|
@@ -8,11 +9,13 @@ module Semlogr
|
|
8
9
|
class Sink
|
9
10
|
include Stud::Buffer
|
10
11
|
|
11
|
-
def initialize(
|
12
|
-
|
13
|
-
@formatter = Formatters::JsonFormatter.new
|
14
|
-
@client = create_client(opts)
|
12
|
+
def initialize(client: nil, formatter: nil, **opts)
|
13
|
+
opts = default_opts.merge(opts)
|
15
14
|
|
15
|
+
@client = client || create_client(opts)
|
16
|
+
@formatter = formatter || ClefFormatter.new
|
17
|
+
|
18
|
+
exit_handler_initialize(opts)
|
16
19
|
buffer_initialize(opts)
|
17
20
|
end
|
18
21
|
|
@@ -24,18 +27,7 @@ module Semlogr
|
|
24
27
|
payload = ''
|
25
28
|
|
26
29
|
log_events.each do |log_event|
|
27
|
-
payload << @formatter.format(log_event)
|
28
|
-
seq_event = event[:properties] || {}
|
29
|
-
seq_event = seq_event.merge(
|
30
|
-
'@t' => event[:timestamp],
|
31
|
-
'@l' => event[:severity],
|
32
|
-
'@mt' => event[:message_template]
|
33
|
-
)
|
34
|
-
|
35
|
-
add_error(seq_event, event[:error])
|
36
|
-
|
37
|
-
seq_event
|
38
|
-
end
|
30
|
+
payload << @formatter.format(log_event)
|
39
31
|
end
|
40
32
|
|
41
33
|
@client.post_events(payload)
|
@@ -43,20 +35,28 @@ module Semlogr
|
|
43
35
|
|
44
36
|
private
|
45
37
|
|
38
|
+
def default_opts
|
39
|
+
{
|
40
|
+
flush_at_exit: true,
|
41
|
+
flush_at_exit_timeout: 10
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def exit_handler_initialize(opts)
|
46
|
+
return unless opts[:flush_at_exit]
|
47
|
+
|
48
|
+
at_exit do
|
49
|
+
flush_timeout = opts[:flush_at_exit_timeout]
|
50
|
+
Timeout.timeout(flush_timeout) { buffer_flush(final: true) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
def create_client(opts)
|
47
55
|
server_url = opts.fetch(:server_url, 'http://localhost:5341')
|
48
56
|
api_key = opts.fetch(:api_key, nil)
|
49
57
|
|
50
58
|
SeqApi.new(server_url, api_key)
|
51
59
|
end
|
52
|
-
|
53
|
-
def add_error(seq_event, error)
|
54
|
-
return unless error
|
55
|
-
seq_event['@x'] = "#{error[:type]}: #{error[:message]}"
|
56
|
-
|
57
|
-
return unless error[:backtrace] && error[:backtrace].any?
|
58
|
-
seq_event['@x'] += "\n\s\s#{error[:backtrace].join("\n\s\s")}"
|
59
|
-
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/semlogr-sinks-seq.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semlogr-sinks-seq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Sedich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -135,11 +135,13 @@ files:
|
|
135
135
|
- ".travis.yml"
|
136
136
|
- CHANGELOG.md
|
137
137
|
- Gemfile
|
138
|
+
- LICENSE.md
|
138
139
|
- README.md
|
139
140
|
- Rakefile
|
140
141
|
- bin/console
|
141
142
|
- bin/setup
|
142
143
|
- lib/semlogr/sinks/seq.rb
|
144
|
+
- lib/semlogr/sinks/seq/clef_formatter.rb
|
143
145
|
- lib/semlogr/sinks/seq/seq_api.rb
|
144
146
|
- lib/semlogr/sinks/seq/sink.rb
|
145
147
|
- lib/semlogr/sinks/seq/version.rb
|
@@ -163,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
165
|
version: '0'
|
164
166
|
requirements: []
|
165
167
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.6.13
|
167
169
|
signing_key:
|
168
170
|
specification_version: 4
|
169
171
|
summary: A semlogr sink for logging to seq.
|