cm_logger 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile.lock +9 -1
- data/cm_logger.gemspec +2 -1
- data/lib/sidekiq_formatter.rb +30 -22
- data/spec/sidekiq_formatter_spec.rb +2 -3
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 183fba83980c764b15c0d3fd5db0da99bc09a29521d21dbb6a458231b49806ef
|
4
|
+
data.tar.gz: cd567fbe9b2ee857b73ad081ef91c216066bed2affe81449496b5d8152d8e713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d76a2918fdf9ec8d1038aec501bd7cfaa7a88652119f2632cd49279128763db4c1d7d2dd5883a428e0e77b575ac11724ffecc58b7c7a50cb8cbef8673fd0ac0
|
7
|
+
data.tar.gz: db8c0e0eefc9a54484c62a3fc7cc774a04c132da2cc0c95ea9ba748ad0d872ef97d76d214c97651a5e00694e524742a2c81a233633070451abbb911579a5fa87
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -7,11 +7,14 @@ GEM
|
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
coderay (1.1.2)
|
10
|
+
connection_pool (2.2.3)
|
10
11
|
diff-lcs (1.3)
|
11
12
|
method_source (1.0.0)
|
12
13
|
pry (0.13.0)
|
13
14
|
coderay (~> 1.1)
|
14
15
|
method_source (~> 1.0)
|
16
|
+
rack (2.2.3)
|
17
|
+
redis (4.2.1)
|
15
18
|
rspec (3.9.0)
|
16
19
|
rspec-core (~> 3.9.0)
|
17
20
|
rspec-expectations (~> 3.9.0)
|
@@ -25,6 +28,10 @@ GEM
|
|
25
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
29
|
rspec-support (~> 3.9.0)
|
27
30
|
rspec-support (3.9.2)
|
31
|
+
sidekiq (6.1.1)
|
32
|
+
connection_pool (>= 2.2.2)
|
33
|
+
rack (~> 2.0)
|
34
|
+
redis (>= 4.2.0)
|
28
35
|
|
29
36
|
PLATFORMS
|
30
37
|
ruby
|
@@ -33,6 +40,7 @@ DEPENDENCIES
|
|
33
40
|
cm_logger!
|
34
41
|
pry
|
35
42
|
rspec (~> 3.9.0)
|
43
|
+
sidekiq (~> 6.1.1)
|
36
44
|
|
37
45
|
BUNDLED WITH
|
38
|
-
2.
|
46
|
+
2.1.4
|
data/cm_logger.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'cm_logger'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.2'
|
7
7
|
s.date = '2020-04-09'
|
8
8
|
s.summary = "Log related stuff for Rails"
|
9
9
|
s.description = "Log related stuff for Rails"
|
@@ -15,4 +15,5 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_ruby_version = '>= 2.6'
|
16
16
|
|
17
17
|
s.add_development_dependency("rspec", ["~> 3.9.0"])
|
18
|
+
s.add_development_dependency("sidekiq", ["~> 6.1.1"])
|
18
19
|
end
|
data/lib/sidekiq_formatter.rb
CHANGED
@@ -1,38 +1,46 @@
|
|
1
|
-
require '
|
2
|
-
require 'time'
|
1
|
+
require 'sidekiq'
|
3
2
|
|
4
3
|
module CmLogger
|
5
|
-
class SidekiqFormatter < Logger::
|
4
|
+
class SidekiqFormatter < ::Sidekiq::Logger::Formatters::Base
|
6
5
|
def call(severity, time, program_name, message)
|
7
|
-
clean_message = message.gsub('"', '\'').gsub("\n", ' ').slice(0, 100)
|
8
|
-
|
9
6
|
log_hash = {
|
10
7
|
time: time.utc.iso8601(3),
|
11
8
|
pid: ::Process.pid,
|
12
|
-
tid:
|
9
|
+
tid: tid,
|
13
10
|
severity: severity,
|
14
|
-
message:
|
15
|
-
|
11
|
+
message: message,
|
12
|
+
worker_name: extract_worker_name,
|
13
|
+
jid: extract_jid,
|
14
|
+
elapsed: extract_elapsed
|
15
|
+
}.compact
|
16
16
|
|
17
17
|
log_hash.keys.map do |key|
|
18
|
-
"#{key}=#{log_hash[key]}"
|
18
|
+
"#{key}=#{sanitize(log_hash[key])}"
|
19
19
|
end.join(" ") + "\n"
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
{
|
30
|
-
worker_name: worker_name,
|
31
|
-
jid: jid
|
32
|
-
}.compact
|
22
|
+
private
|
23
|
+
|
24
|
+
def sanitize(message)
|
25
|
+
result = message.to_s.gsub('"', '\'').gsub("\n", ' ').slice(0, 100)
|
26
|
+
|
27
|
+
if /\s/.match?(result)
|
28
|
+
"\"#{result}\""
|
33
29
|
else
|
34
|
-
|
30
|
+
result
|
35
31
|
end
|
36
32
|
end
|
33
|
+
|
34
|
+
def extract_worker_name
|
35
|
+
ctx[:class]
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_jid
|
39
|
+
ctx[:jid]
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_elapsed
|
43
|
+
ctx[:elapsed]
|
44
|
+
end
|
37
45
|
end
|
38
|
-
end
|
46
|
+
end
|
@@ -6,7 +6,7 @@ describe 'CmLogger::SidekiqFormatter' do
|
|
6
6
|
CmLogger::SidekiqFormatter.new
|
7
7
|
end
|
8
8
|
let(:severity) { "INFO" }
|
9
|
-
let(:message) { "xxx" }
|
9
|
+
let(:message) { "xxx xxx" }
|
10
10
|
let(:time) { Time.now }
|
11
11
|
let(:program_name) { "program_name" }
|
12
12
|
|
@@ -15,9 +15,8 @@ describe 'CmLogger::SidekiqFormatter' do
|
|
15
15
|
|
16
16
|
result = formatter.call(*args)
|
17
17
|
|
18
|
-
tid = Thread.current.object_id.to_s(36)
|
19
18
|
pid = ::Process.pid
|
20
|
-
expect(result).to eq("time=#{time.utc.iso8601(3)} pid=#{pid} tid=#{tid} severity=#{severity} message=\"#{message}\"\n")
|
19
|
+
expect(result).to eq("time=#{time.utc.iso8601(3)} pid=#{pid} tid=#{formatter.tid} severity=#{severity} message=\"#{message}\"\n")
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cm_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ben
|
@@ -24,12 +24,28 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.1.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.1.1
|
27
41
|
description: Log related stuff for Rails
|
28
42
|
email: ben@arc.dev
|
29
43
|
executables: []
|
30
44
|
extensions: []
|
31
45
|
extra_rdoc_files: []
|
32
46
|
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- CHANGELOG.md
|
33
49
|
- Gemfile
|
34
50
|
- Gemfile.lock
|
35
51
|
- README.md
|