kitlog 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +46 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +64 -0
- data/README.md +19 -0
- data/kitlog.gemspec +26 -0
- data/lib/kitlog.rb +59 -0
- data/spec/lib/kitlog_spec.rb +34 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dbfb04c9827d7c0c8eec169408abfeed397862a1c09e56e86addc8279c22df28
|
4
|
+
data.tar.gz: 7521afef6761be82e66f30649eab7c7b61a9018f5d00a4896b54fb0d8cae0289
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1988af1b796d22ca32e44f52bbf6320a1bc48c2769e2281877a7f87e8f3b5d5a22f8e120779bfeb1884f1a94947d90224d1f036c732413fdd0364eefe9b5db8b
|
7
|
+
data.tar.gz: db2bc7e901db3af7a32d24cf32b84d643d92d036b60b94246c907d9eeede4dad8e948555a52c1a003ba2d1f8f50f37b96adafed2a1f9ee7e28d78adb4c81f746
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
version: 2
|
3
|
+
|
4
|
+
references:
|
5
|
+
bundle_install: &bundle_install
|
6
|
+
run:
|
7
|
+
name: Bundle
|
8
|
+
command: gem install bundler && bundle install --path vendor/bundle --jobs=4 --retry=3
|
9
|
+
|
10
|
+
cache_bundle_for_lockfile: &cache_bundle_for_lockfile
|
11
|
+
save_cache:
|
12
|
+
key: ruby2.6.5-Gemfile-{{ checksum "Gemfile.lock" }}
|
13
|
+
paths:
|
14
|
+
- vendor/bundle
|
15
|
+
|
16
|
+
cache_bundle: &cache_bundle
|
17
|
+
save_cache:
|
18
|
+
key: ruby2.6.5-Gemfile
|
19
|
+
paths:
|
20
|
+
- vendor/bundle
|
21
|
+
|
22
|
+
restore_bundle: &restore_bundle
|
23
|
+
restore_cache:
|
24
|
+
keys:
|
25
|
+
- ruby2.6.5-Gemfile-{{ checksum "Gemfile.lock" }}
|
26
|
+
- ruby2.6.5-Gemfile
|
27
|
+
|
28
|
+
jobs:
|
29
|
+
build:
|
30
|
+
docker:
|
31
|
+
- image: "ruby:2.6.5"
|
32
|
+
working_directory: ~/kitlog
|
33
|
+
steps:
|
34
|
+
- checkout
|
35
|
+
- *restore_bundle
|
36
|
+
- *bundle_install
|
37
|
+
- *cache_bundle_for_lockfile
|
38
|
+
- *cache_bundle
|
39
|
+
- run: bundle exec rubocop
|
40
|
+
- run: bundle exec rspec
|
41
|
+
|
42
|
+
workflows:
|
43
|
+
version: 2
|
44
|
+
test:
|
45
|
+
jobs:
|
46
|
+
- build
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kitlog (1.0.0)
|
5
|
+
values (~> 1.8)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
gc_ruboconfig (2.8.0)
|
14
|
+
rubocop (>= 0.77)
|
15
|
+
rubocop-performance (~> 1.5)
|
16
|
+
rubocop-rspec (>= 1.33.0)
|
17
|
+
jaro_winkler (1.5.4)
|
18
|
+
method_source (0.9.2)
|
19
|
+
parallel (1.19.1)
|
20
|
+
parser (2.6.5.0)
|
21
|
+
ast (~> 2.4.0)
|
22
|
+
pry (0.12.2)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
25
|
+
rainbow (3.0.0)
|
26
|
+
rspec (3.9.0)
|
27
|
+
rspec-core (~> 3.9.0)
|
28
|
+
rspec-expectations (~> 3.9.0)
|
29
|
+
rspec-mocks (~> 3.9.0)
|
30
|
+
rspec-core (3.9.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-expectations (3.9.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-mocks (3.9.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-support (3.9.0)
|
39
|
+
rubocop (0.77.0)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.6)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
46
|
+
rubocop-performance (1.5.1)
|
47
|
+
rubocop (>= 0.71.0)
|
48
|
+
rubocop-rspec (1.37.0)
|
49
|
+
rubocop (>= 0.68.1)
|
50
|
+
ruby-progressbar (1.10.1)
|
51
|
+
unicode-display_width (1.6.0)
|
52
|
+
values (1.8.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
gc_ruboconfig (= 2.8.0)
|
59
|
+
kitlog!
|
60
|
+
pry (~> 0.10)
|
61
|
+
rspec (~> 3.8)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# kitlog [![CircleCI](https://circleci.com/gh/lawrencejones/kitlog.svg?style=svg)](https://circleci.com/gh/lawrencejones/kitlog)
|
2
|
+
|
3
|
+
The smallest of logging libraries that imitates the go-kit logger interface.
|
4
|
+
Super simple, just:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
irb(main):001:0> require "kitlog"
|
8
|
+
|
9
|
+
irb(main):002:0> Kitlog.log(event: "hello, from a terminal")
|
10
|
+
event="hello, from a terminal" ts="2019-12-16T11:23:07.908104000Z" tid=70217581666320
|
11
|
+
|
12
|
+
irb(main):003:0> Kitlog.configure(format: :json)
|
13
|
+
irb(main):004:0> Kitlog.log(event: "hello, with json")
|
14
|
+
{"event":"hello, with json","ts":"2019-12-16T11:23:27.448655000Z","tid":70217581666320}
|
15
|
+
|
16
|
+
irb(main):005:0> logger = Kitlog.with(component: "app");
|
17
|
+
irb(main):006:0> logger.log(event: "ping")
|
18
|
+
{"component":"app","event":"ping","ts":"2019-12-16T11:23:46.460129000Z","tid":70217581666320}
|
19
|
+
```
|
data/kitlog.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kitlog"
|
8
|
+
spec.version = "1.0.0"
|
9
|
+
spec.summary = "Logger for Ruby that imitates go-kit logger"
|
10
|
+
spec.authors = %w[me@lawrencejones.dev]
|
11
|
+
spec.homepage = "https://github.com/lawrencejones/kitlog"
|
12
|
+
spec.email = %w[me@lawrencejones.dev]
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.required_ruby_version = ">= 2.4"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "values", "~> 1.8"
|
22
|
+
|
23
|
+
spec.add_development_dependency "gc_ruboconfig", "= 2.8.0"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
26
|
+
end
|
data/lib/kitlog.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "values"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Kitlog
|
8
|
+
class ContextualLogger < Value.new(:logger, :context)
|
9
|
+
def log(**kwargs)
|
10
|
+
logger.info(context.merge(kwargs))
|
11
|
+
end
|
12
|
+
|
13
|
+
def with(additional_context)
|
14
|
+
super(context: context.merge(additional_context))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
FORMATTERS = {
|
19
|
+
json: ->(payload) { payload.to_json },
|
20
|
+
logfmt: ->(payload) do
|
21
|
+
payload.reduce("") { |a, (k, v)| a + "#{k}=#{v.to_json} " }
|
22
|
+
end,
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
# rubocop:disable Metrics/MethodLength
|
26
|
+
def self.configure(destination: STDERR, format: nil)
|
27
|
+
format ||= destination.isatty ? :logfmt : :json
|
28
|
+
formatter = FORMATTERS.fetch(format)
|
29
|
+
|
30
|
+
@logger = Logger.new(destination)
|
31
|
+
@logger.formatter = proc do |_severity, datetime, _progname, payload|
|
32
|
+
formatter.call(
|
33
|
+
payload.merge(
|
34
|
+
ts: datetime.strftime("%Y-%m-%dT%H:%M:%S.%NZ"),
|
35
|
+
tid: Thread.current.object_id,
|
36
|
+
),
|
37
|
+
) + "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
41
|
+
|
42
|
+
configure
|
43
|
+
|
44
|
+
def self.logger
|
45
|
+
@logger
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.with(**context)
|
49
|
+
ContextualLogger.new(@logger, context)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.log(**kwargs)
|
53
|
+
@logger.info(kwargs)
|
54
|
+
end
|
55
|
+
|
56
|
+
def log(**kwargs)
|
57
|
+
@logger.info(kwargs)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rspec"
|
4
|
+
require "kitlog"
|
5
|
+
|
6
|
+
RSpec.describe(Kitlog) do
|
7
|
+
subject(:output) { StringIO.new }
|
8
|
+
|
9
|
+
let(:logger) { described_class }
|
10
|
+
|
11
|
+
before { described_class.configure(destination: output) }
|
12
|
+
|
13
|
+
def maybe_parse(output)
|
14
|
+
JSON.parse(output.string)
|
15
|
+
rescue JSON::ParserError
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "logs in valid JSON format" do
|
20
|
+
expect { logger.log(event: "hey") }.
|
21
|
+
to change { maybe_parse(output) }.
|
22
|
+
to(include("event" => "hey"))
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".with" do
|
26
|
+
let(:logger) { described_class.with(component: "app") }
|
27
|
+
|
28
|
+
it "persists additional keys into other log messages" do
|
29
|
+
expect { logger.log(event: "hey") }.
|
30
|
+
to change { maybe_parse(output) }.
|
31
|
+
to(include("component" => "app", "event" => "hey"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- me@lawrencejones.dev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: values
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gc_ruboconfig
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.8.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- me@lawrencejones.dev
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".circleci/config.yml"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".ruby-version"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- README.md
|
83
|
+
- kitlog.gemspec
|
84
|
+
- lib/kitlog.rb
|
85
|
+
- spec/lib/kitlog_spec.rb
|
86
|
+
homepage: https://github.com/lawrencejones/kitlog
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.4'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Logger for Ruby that imitates go-kit logger
|
109
|
+
test_files:
|
110
|
+
- spec/lib/kitlog_spec.rb
|