twiglet 2.2.0 → 2.3.4

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
2
  SHA256:
3
- metadata.gz: 356d8c7fec6c41823029cc36bef1cc49bacae6157342b251e9b57f49dcb8151f
4
- data.tar.gz: bd58a67b48daa9bf6108dc78098f46ad0204f98ca600c29bacd713f6cb54ea2e
3
+ metadata.gz: 566cfbc6b21d6429cbdc6554befd8e4b721af7bde6f44de190e883bdbc2f2c17
4
+ data.tar.gz: 5202227657bcc217a0d2bac7b523f09887cc8b5f3449a6d94d1670a54bb5d549
5
5
  SHA512:
6
- metadata.gz: 4bc443482b93b1bba853fbe67605d9b0673830726cf1ef89e941860bc7f832d1efb5f82d5890197ae279b9edf97bf19edf8dc2d8bf61d56d082d6e641f94a245
7
- data.tar.gz: 8d5e178fca01957147dca807aab4117958b18514d568440e72f53cfc8931aad62035a71633646776368f4409d9be48ab8598c66aad4347edd59f79a0bfc281ae
6
+ metadata.gz: e21fdf10a73403d168464f0186f88072549b9770d6b0456848e75dc5a445aecbfd9758f98e3cb1ba83ba2216ce74a8e37ce68a523aa888f35cadc90d53981f34
7
+ data.tar.gz: 38ed9e4fa093acd5f2e974b3a61bfa1543831320f5b2687b3e35a235048c068dadf06d2d5b7e7078eeb3803f111037d8a5358e19a5b3cf0485b3d5a547c50bc2
@@ -1,3 +1,4 @@
1
1
  # Add your project owners info here
2
2
  # More information: https://help.github.com/articles/about-codeowners/
3
- * @simplybusiness/application-tooling
3
+ * @simplybusiness/silversmiths
4
+
@@ -0,0 +1,26 @@
1
+ name: Publish Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build and Publish
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby 2.6
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ version: 2.6.x
17
+ - name: Publish to RubyGems
18
+ run: |
19
+ mkdir -p $HOME/.gem
20
+ touch $HOME/.gem/credentials
21
+ chmod 0600 $HOME/.gem/credentials
22
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
23
+ gem build *.gemspec
24
+ gem push *.gem
25
+ env:
26
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
@@ -3,8 +3,6 @@ name: Ruby CI
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - '*' # matches every branch
7
- - '*/*' # matches every branch containing a single '/'
8
6
 
9
7
  jobs:
10
8
  build:
@@ -30,3 +28,6 @@ jobs:
30
28
  - name: Run all tests
31
29
  run: bundle exec rake test
32
30
  shell: bash
31
+ - name: Run example_app
32
+ run: bundle exec ruby example_app.rb
33
+ shell: bash
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ Gemfile.lock
2
3
  *.rbc
3
4
  /.config
4
5
  /coverage/
data/README.md CHANGED
@@ -22,7 +22,9 @@ A hash can optionally be passed in as a keyword argument for `default_properties
22
22
 
23
23
  You may also provide an optional `output` keyword argument which should be an object with a `puts` method - like `$stdout`.
24
24
 
25
- Lastly, you can provide another optional keyword argument called `now`, which should be a function returning a `Time` string in ISO8601 format.
25
+ In addition, you can provide another optional keyword argument called `now`, which should be a function returning a `Time` string in ISO8601 format.
26
+
27
+ Lastly, you may provide the optional keyword argument `level` to initialize the logger with a severity threshold. Alternatively, the threshold can be updated at runtime by calling the `level` instance method.
26
28
 
27
29
  The defaults for both `output` and `now` should serve for most uses, though you may want to override them for testing as we have done [here](test/logger_test.rb).
28
30
 
@@ -63,6 +63,7 @@ module Twiglet
63
63
  .deep_merge(@default_properties.to_nested)
64
64
  .deep_merge(message.to_nested)
65
65
  .to_json
66
+ .concat("\n")
66
67
  end
67
68
  end
68
69
  end
@@ -3,7 +3,7 @@
3
3
  require 'logger'
4
4
  require 'time'
5
5
  require 'json'
6
- require 'twiglet/formatter'
6
+ require_relative 'formatter'
7
7
  require_relative '../hash_extensions'
8
8
 
9
9
  module Twiglet
@@ -14,17 +14,19 @@ module Twiglet
14
14
  service_name,
15
15
  default_properties: {},
16
16
  now: -> { Time.now.utc },
17
- output: $stdout
17
+ output: $stdout,
18
+ level: Logger::DEBUG
18
19
  )
19
20
  @service_name = service_name
20
21
  @now = now
21
22
  @output = output
23
+ @level = level
22
24
 
23
25
  raise 'Service name is mandatory' \
24
26
  unless service_name.is_a?(String) && !service_name.strip.empty?
25
27
 
26
28
  formatter = Twiglet::Formatter.new(service_name, default_properties: default_properties, now: now)
27
- super(output, formatter: formatter)
29
+ super(output, formatter: formatter, level: level)
28
30
  end
29
31
 
30
32
  def error(message = {}, error = nil, &block)
@@ -45,7 +47,8 @@ module Twiglet
45
47
  Logger.new(@service_name,
46
48
  default_properties: default_properties,
47
49
  now: @now,
48
- output: @output)
50
+ output: @output,
51
+ level: @level)
49
52
  end
50
53
 
51
54
  alias_method :warning, :warn
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '2.2.0'
4
+ VERSION = '2.3.4'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require 'minitest/autorun'
4
4
  require_relative '../lib/twiglet/logger'
5
5
 
6
+ # rubocop:disable Metrics/BlockLength
6
7
  describe Twiglet::Logger do
7
8
  before do
8
9
  @now = -> { Time.utc(2020, 5, 11, 15, 1, 1) }
@@ -130,6 +131,21 @@ describe Twiglet::Logger do
130
131
  assert_equal 'Guinea pigs arrived', log[:message]
131
132
  end
132
133
 
134
+ it "should log multiple messages properly" do
135
+ @logger.debug({message: 'hi'})
136
+ @logger.info({message: 'there'})
137
+
138
+ expected_output =
139
+ '{"@timestamp":"2020-05-11T15:01:01.000Z",'\
140
+ '"service":{"name":"petshop"},"log":{"level":"debug"},"message":"hi"}'\
141
+ "\n"\
142
+ '{"@timestamp":"2020-05-11T15:01:01.000Z",'\
143
+ '"service":{"name":"petshop"},"log":{"level":"info"},"message":"there"}'\
144
+ "\n"\
145
+
146
+ assert_equal expected_output, @buffer.string
147
+ end
148
+
133
149
  it 'should be able to convert dotted keys to nested objects' do
134
150
  @logger.debug({
135
151
  "trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
@@ -289,6 +305,10 @@ describe Twiglet::Logger do
289
305
  assert_equal args[:level], @logger.level
290
306
  end
291
307
  end
308
+
309
+ it 'initializes the logger with the provided level' do
310
+ assert_equal Logger::WARN, Twiglet::Logger.new('petshop', level: :warn).level
311
+ end
292
312
  end
293
313
 
294
314
  private
@@ -298,3 +318,4 @@ describe Twiglet::Logger do
298
318
  JSON.parse(buffer.read, symbolize_names: true)
299
319
  end
300
320
  end
321
+ # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twiglet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-22 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Like a log, only smaller.
14
14
  email:
@@ -18,13 +18,13 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".github/CODEOWNERS"
21
+ - ".github/workflows/gem-publish.yml"
21
22
  - ".github/workflows/ruby.yml"
22
23
  - ".gitignore"
23
24
  - ".rubocop.yml"
24
25
  - ".ruby-version"
25
26
  - CODE_OF_CONDUCT.md
26
27
  - Gemfile
27
- - Gemfile.lock
28
28
  - LICENSE
29
29
  - RATIONALE.md
30
30
  - README.md
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubygems_version: 3.0.8
60
+ rubygems_version: 3.0.3
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Twiglet
@@ -1,62 +0,0 @@
1
- GIT
2
- remote: https://github.com/simplybusiness/simplycop.git
3
- revision: 02b417277e3ff9eeab34d6b7c30a95a17d876731
4
- specs:
5
- simplycop (0.5.4)
6
- rubocop (~> 0.80.0)
7
- rubocop-rails
8
- rubocop-rspec
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- activesupport (6.0.3.1)
14
- concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.2, >= 2.2.2)
19
- ast (2.4.0)
20
- concurrent-ruby (1.1.6)
21
- i18n (1.8.2)
22
- concurrent-ruby (~> 1.0)
23
- jaro_winkler (1.5.4)
24
- minitest (5.14.0)
25
- parallel (1.19.1)
26
- parser (2.7.1.3)
27
- ast (~> 2.4.0)
28
- rack (2.2.2)
29
- rainbow (3.0.0)
30
- rake (13.0.1)
31
- rexml (3.2.4)
32
- rubocop (0.80.1)
33
- jaro_winkler (~> 1.5.1)
34
- parallel (~> 1.10)
35
- parser (>= 2.7.0.1)
36
- rainbow (>= 2.2.2, < 4.0)
37
- rexml
38
- ruby-progressbar (~> 1.7)
39
- unicode-display_width (>= 1.4.0, < 1.7)
40
- rubocop-rails (2.5.2)
41
- activesupport
42
- rack (>= 1.1)
43
- rubocop (>= 0.72.0)
44
- rubocop-rspec (1.39.0)
45
- rubocop (>= 0.68.1)
46
- ruby-progressbar (1.10.1)
47
- thread_safe (0.3.6)
48
- tzinfo (1.2.7)
49
- thread_safe (~> 0.1)
50
- unicode-display_width (1.6.1)
51
- zeitwerk (2.3.0)
52
-
53
- PLATFORMS
54
- ruby
55
-
56
- DEPENDENCIES
57
- minitest
58
- rake
59
- simplycop!
60
-
61
- BUNDLED WITH
62
- 2.1.4