sidekiq-logging-json 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/sidekiq/logging/json.rb +38 -0
- data/lib/sidekiq/logging/json/version.rb +7 -0
- data/sidekiq-logging-json.gemspec +31 -0
- data/spec/sidekiq/logging/json_spec.rb +31 -0
- data/spec/spec_helper.rb +9 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc9b1930649549a4d84514f6c00e608b7cb9955b
|
4
|
+
data.tar.gz: f05ea0ec054aa1f083b42cc32b3fda446db1b63e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f136cdbf07b220d7684a4c3950937a0a8324ec3cae569df404bed9c09ef80d73984c230b01b0bf6c7faae3d0841b9077fa86479c914dcab8669ee89670505cc7
|
7
|
+
data.tar.gz: 7ff1aa34324ef09722def61c81f89ed59b2802c67b1705ba2c208635a32e7f4bd2b80323aca3cdd62da525847274ec60f8b1d35a0c17937aa719840e3525e17d
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Wouter de Vos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Sidekiq::Logging::Json
|
2
|
+
|
3
|
+
At [Springest](http://www.springest.com), we use
|
4
|
+
[Logstash](http://logstash.net/) to ship all our logs to
|
5
|
+
[Elasticsearch](http://www.elasticsearch.org/). An Elasticsearch index
|
6
|
+
consists of JSON documents. To make it possible to make fine grained
|
7
|
+
queries on [Sidekiq](http://sidekiq.org/) logs, we needed logging in
|
8
|
+
JSON format. This gem contains that logger.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'sidekiq-logging-json'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ gem install sidekiq-logging-json
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Add this to your Sidekiq configuration:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'sidekiq/logging/json'
|
36
|
+
|
37
|
+
Sidekiq.logger.formatter = Sidekiq::Logging::Json::Logger.new
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/[my-github-username]/sidekiq-logging-json/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "sidekiq/logging/json/version"
|
2
|
+
require "sidekiq/logging/json"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module Logging
|
7
|
+
module Json
|
8
|
+
class Logger < Sidekiq::Logging::Pretty
|
9
|
+
# Provide a call() method that returns the formatted message.
|
10
|
+
def call(severity, time, program_name, message)
|
11
|
+
{
|
12
|
+
'@timestamp' => time.utc.iso8601,
|
13
|
+
:pid => ::Process.pid,
|
14
|
+
:tid => "TID-#{Thread.current.object_id.to_s(36)}",
|
15
|
+
:context => "#{context}",
|
16
|
+
:severity => severity,
|
17
|
+
:program_name => program_name,
|
18
|
+
:type => 'sidekiq',
|
19
|
+
:status => nil,
|
20
|
+
:run_time => nil
|
21
|
+
}.merge(processed_message(message)).to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_message(message)
|
25
|
+
result = message.match(/INFO: (done|start)(: ([0-9\.]+) sec)?$/)
|
26
|
+
|
27
|
+
return { message: message } unless result
|
28
|
+
|
29
|
+
{
|
30
|
+
:message => message, # The full message
|
31
|
+
:status => result[1], # start or done
|
32
|
+
:run_time => result[3] && result[3].to_f # run time in seconds
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/logging/json/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sidekiq-logging-json"
|
8
|
+
spec.version = Sidekiq::Logging::Json::VERSION
|
9
|
+
spec.authors = ["Wouter de Vos"]
|
10
|
+
spec.email = ["wouter@springest.com"]
|
11
|
+
spec.summary = %q{Sidekiq JSON log format, e.g. for Logstash.}
|
12
|
+
spec.description = <<-DESC
|
13
|
+
At Springest, we use Logstash to ship all our logs to Elasticsearch. An Elasticsearch index consists of JSON documents.
|
14
|
+
To make it possible to make fine grained queries on Sidekiq logs, we needed logging in JSON format.
|
15
|
+
|
16
|
+
This gem contains that logger.
|
17
|
+
DESC
|
18
|
+
spec.homepage = "https://github.com/Springest/Sidekiq-Logging-JSON"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0")
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
spec.add_development_dependency "rake", "~> 10"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3"
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "sidekiq", "~> 3"
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Sidekiq::Logging::Json" do
|
4
|
+
describe "process_message" do
|
5
|
+
subject { Sidekiq::Logging::Json::Logger.new.process_message(logentry) }
|
6
|
+
let(:logentry) { "Some random message" }
|
7
|
+
let(:message) { subject[:message] }
|
8
|
+
let(:status) { subject[:status] }
|
9
|
+
let(:run_time) { subject[:run_time] }
|
10
|
+
|
11
|
+
it { expect( message ).to eq(logentry) }
|
12
|
+
it { expect( status ).to eq(nil) }
|
13
|
+
it { expect( run_time ).to eq(nil) }
|
14
|
+
|
15
|
+
context "start" do
|
16
|
+
let(:logentry) { "2014-06-05T12:38:55Z 8630 TID-osanfu5nw SubjectClickthroughTracker JID-e17a9e9ca0521bb74b423166 INFO: start" }
|
17
|
+
|
18
|
+
it { expect( message ).to eq(logentry) }
|
19
|
+
it { expect( status ).to eq("start") }
|
20
|
+
it { expect( run_time ).to eq(nil) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "done" do
|
24
|
+
let(:logentry) { "2014-06-05T12:38:42Z 8630 TID-osammcf2k TrainingIndexer::Work JID-177066e96052c2314dcad8c7 INFO: done: 51.579 sec" }
|
25
|
+
|
26
|
+
it { expect( message ).to eq(logentry) }
|
27
|
+
it { expect( status ).to eq("done") }
|
28
|
+
it { expect( run_time ).to eq(51.579) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-logging-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wouter de Vos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sidekiq
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description: |
|
70
|
+
At Springest, we use Logstash to ship all our logs to Elasticsearch. An Elasticsearch index consists of JSON documents.
|
71
|
+
To make it possible to make fine grained queries on Sidekiq logs, we needed logging in JSON format.
|
72
|
+
|
73
|
+
This gem contains that logger.
|
74
|
+
email:
|
75
|
+
- wouter@springest.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- .rspec
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/sidekiq/logging/json.rb
|
87
|
+
- lib/sidekiq/logging/json/version.rb
|
88
|
+
- sidekiq-logging-json.gemspec
|
89
|
+
- spec/sidekiq/logging/json_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/Springest/Sidekiq-Logging-JSON
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Sidekiq JSON log format, e.g. for Logstash.
|
115
|
+
test_files:
|
116
|
+
- spec/sidekiq/logging/json_spec.rb
|
117
|
+
- spec/spec_helper.rb
|