trifle-logger 0.1.4 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a70cfb4b0863b2ac9fff7a44addd56264090c463ba53504cbcb2534ac74c09e
4
- data.tar.gz: 759fb8c95b1df65a8571290809e9c6ffdd23bd6f835d722613a87e8da3900402
3
+ metadata.gz: a66e51428a8489d5edc94ab57d8350199d5bb17ca69478dc7075910d82c5b51c
4
+ data.tar.gz: cf8fe7cda52c6ff20b50152b83d9f42719d140b8e10f94b415532ffe289c652b
5
5
  SHA512:
6
- metadata.gz: 7fd33b88c7a6c4ba9b87802af9eddbbe9884bef360d2b5c0a173b4ae3e830a679197adbea94e12ca0b6984e05949d745bf4b155db04ec1a4324cb6bdd8468aa7
7
- data.tar.gz: 40e67bc2924dc8ebc424cc54415970683b4edd38d73eb373f97d4f9854fd3febeb75399b17f8d1f920dd062c0525506213568e8ec9a5beaabcf57445d80c1882
6
+ metadata.gz: be7209a804399fa1b02a8c6dd13e20415aa843b2784048904328100102dca07e9855386d1ba7507151e25253fc5a7cbe8775a625be2bd6e717d5f95c944a9003
7
+ data.tar.gz: 5a536d5d6c741719eb6b5eb20e989747f873815f59edac421c6ff667a9ab3190f4e7314f8fcbe244ce613e751b865726661ef5cece265fb61746752db1ae9804
@@ -9,29 +9,28 @@ name: Ruby
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ main ]
12
+ branches: [main]
13
13
  pull_request:
14
- branches: [ main ]
14
+ branches: [main]
15
15
 
16
16
  jobs:
17
17
  test:
18
-
19
18
  runs-on: ubuntu-latest
20
19
  strategy:
21
20
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
21
+ ruby-version: ["3.0"]
23
22
 
24
23
  steps:
25
- - uses: actions/checkout@v2
26
- - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
- with:
32
- ruby-version: ${{ matrix.ruby-version }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Rspec
35
- run: bundle exec rspec
36
- - name: Rubocop
37
- run: bundle exec rubocop
24
+ - uses: actions/checkout@v2
25
+ - name: Set up Ruby
26
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
28
+ # uses: ruby/setup-ruby@v1
29
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: Rspec
34
+ run: bundle exec rspec
35
+ - name: Rubocop
36
+ run: bundle exec rubocop
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.3.0] - 2022-01-11
4
+
5
+ - Feat: Rename tracer_klass to tracer_class and use it consistently through middlewares
6
+
7
+ ## [0.2.2] - 2022-01-11
8
+
9
+ - Feat: Allow tracer to accept custom configuration
10
+
11
+ ## [0.2.1] - 2021-06-11
12
+
13
+ - Chore: Update license
14
+ - Chore: Drop ruby 2.x
15
+
16
+ ## [0.2.0] - 2021-06-1
17
+
18
+ - Feat: Add callbacks
19
+
20
+ ## [0.1.x] - 2021-03-29
21
+
22
+ - Chore: Bunch of initial commits :)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trifle-logger (0.1.4)
4
+ trifle-logger (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,17 +3,28 @@
3
3
  module Trifle
4
4
  module Logger
5
5
  class Configuration
6
- attr_accessor :tracer_klass, :callbacks
6
+ attr_accessor :tracer_class, :callbacks, :bump_every
7
7
 
8
8
  def initialize
9
- @tracer_klass = Trifle::Logger::Tracer::Hash
10
- @callbacks = {
11
- wrapup: []
12
- }
9
+ @tracer_class = Trifle::Logger::Tracer::Hash
10
+ @callbacks = { liftoff: [], bump: [], wrapup: [] }
11
+ @bump_every = 15.seconds
12
+ end
13
+
14
+ def on_liftoff(tracer)
15
+ @callbacks.fetch(:liftoff, []).map do |c|
16
+ c.call(tracer)
17
+ end
18
+ end
19
+
20
+ def on_bump(tracer)
21
+ @callbacks.fetch(:bump, []).map do |c|
22
+ c.call(tracer)
23
+ end
13
24
  end
14
25
 
15
26
  def on_wrapup(tracer)
16
- @callbacks.fetch(:wrapup, []).each do |c|
27
+ @callbacks.fetch(:wrapup, []).map do |c|
17
28
  c.call(tracer)
18
29
  end
19
30
  end
@@ -9,7 +9,8 @@ module Trifle
9
9
  end
10
10
 
11
11
  def call(env)
12
- # Trifle::Logger.tracer = Trifle::Logger::Tracer::Hash.new
12
+ # TODO: set up key
13
+ # Trifle::Logger.tracer = Trifle::Logger.default.tracer_class.new
13
14
  @status, @headers, @response = @app.call(env)
14
15
  rescue => e # rubocop:disable Style/RescueStandardError
15
16
  Trifle::Logger.tracer&.trace("Exception: #{e}", state: :error)
@@ -17,7 +17,7 @@ module Trifle
17
17
 
18
18
  module InstanceMethods
19
19
  def with_trifle_logger
20
- Trifle::Logger.tracer = Trifle::Logger::Tracer::Hash.new(
20
+ Trifle::Logger.tracer = Trifle::Logger.default.tracer_class.new(
21
21
  key: trace_key, meta: trace_meta
22
22
  )
23
23
  yield
@@ -18,7 +18,7 @@ module Trifle
18
18
  def tracer_for(job:)
19
19
  return nil unless job['logger_key']
20
20
 
21
- Trifle::Logger.default.tracer_klass.new(
21
+ Trifle::Logger.default.tracer_class.new(
22
22
  key: job['logger_key'], meta: job['args']
23
23
  )
24
24
  end
@@ -4,19 +4,29 @@ module Trifle
4
4
  module Logger
5
5
  module Tracer
6
6
  class Hash
7
- attr_accessor :key, :meta, :data, :tags, :artifacts, :state, :ignore
7
+ attr_accessor :key, :meta, :data, :tags, :artifacts, :state, :ignore, :reference
8
8
 
9
- def initialize(key:, meta: nil)
9
+ def initialize(key:, meta: nil, config: nil)
10
10
  @key = key
11
11
  @meta = meta
12
+ @config = config
13
+ set_defaults!
14
+
15
+ trace("Tracer has been initialized for #{key}")
16
+ @reference = liftoff.first
17
+ end
18
+
19
+ def set_defaults!
12
20
  @data = []
13
21
  @tags = []
14
22
  @artifacts = []
15
- @state = :success
23
+ @state = :running
16
24
  @ignore = false
17
25
  @result_prefix = '=> '
26
+ end
18
27
 
19
- trace("Trifle::Trace has been initialized for #{key}")
28
+ def config
29
+ @config || Trifle::Logger.default
20
30
  end
21
31
 
22
32
  def keys
@@ -24,7 +34,7 @@ module Trifle
24
34
  parts.count.times.map { |i| parts[0..i].join('/') }
25
35
  end
26
36
 
27
- def trace(message, state: :success, head: false)
37
+ def trace(message, state: :success, head: false) # rubocop:disable Metrics/MethodLength
28
38
  result = yield if block_given?
29
39
  rescue => e # rubocop:disable Style/RescueStandardError
30
40
  raise e
@@ -34,6 +44,7 @@ module Trifle
34
44
  head: head, state: block_given? && result.nil? || e ? :error : state
35
45
  )
36
46
  dump_result(result) if block_given?
47
+ bump
37
48
  result
38
49
  end
39
50
 
@@ -57,6 +68,8 @@ module Trifle
57
68
 
58
69
  def tag(tag)
59
70
  @tags << tag
71
+ bump
72
+ tag
60
73
  end
61
74
 
62
75
  def artifact(name, path)
@@ -65,6 +78,8 @@ module Trifle
65
78
  state: :success, head: false, meta: false, media: true
66
79
  }
67
80
  @artifacts << path
81
+ bump
82
+ path
68
83
  end
69
84
 
70
85
  def fail!
@@ -75,16 +90,37 @@ module Trifle
75
90
  @state = :warning
76
91
  end
77
92
 
93
+ def success!
94
+ @state = :success
95
+ end
96
+
78
97
  def success?
79
98
  @state == :success
80
99
  end
81
100
 
101
+ def running?
102
+ @state == :running
103
+ end
104
+
82
105
  def ignore!
83
106
  @ignore = true
84
107
  end
85
108
 
109
+ def liftoff
110
+ @bumped_at = now
111
+ config.on_liftoff(self)
112
+ end
113
+
114
+ def bump
115
+ return unless @bumped_at && @bumped_at <= now - config.bump_every
116
+
117
+ @bumped_at = now
118
+ config.on_bump(self)
119
+ end
120
+
86
121
  def wrapup
87
- Trifle::Logger.default.on_wrapup(self) unless @ignore
122
+ success! if running?
123
+ config.on_wrapup(self)
88
124
  end
89
125
  end
90
126
  end
@@ -18,6 +18,10 @@ module Trifle
18
18
 
19
19
  def ignore!; end
20
20
 
21
+ def liftoff; end
22
+
23
+ def bump; end
24
+
21
25
  def wrapup; end
22
26
  end
23
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Logger
5
- VERSION = '0.1.4'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -1,28 +1,30 @@
1
1
  require_relative 'lib/trifle/logger/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "trifle-logger"
4
+ spec.name = 'trifle-logger'
5
5
  spec.version = Trifle::Logger::VERSION
6
- spec.authors = ["Jozef Vaclavik"]
7
- spec.email = ["jozef@hey.com"]
6
+ spec.authors = ['Jozef Vaclavik']
7
+ spec.email = ['jozef@hey.com']
8
8
 
9
9
  spec.summary = 'Simple logger backed by Hash'
10
10
  spec.description = 'Trifle::Logger is a way too simple timeline logger '\
11
11
  'that helps you track custom outputs.'
12
12
  spec.homepage = 'https://trifle.io'
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6")
13
+ spec.licenses = ['MIT']
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
14
15
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata['homepage_uri'] = spec.homepage
16
17
  spec.metadata['source_code_uri'] = 'https://github.com/trifle-io/trifle-logger'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/trifle-io/trifle-logger/blob/main/CHANGELOG.md'
17
19
 
18
20
  # Specify which files should be added to the gem when it is released.
19
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
22
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
24
  end
23
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
24
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
27
+ spec.require_paths = ['lib']
26
28
 
27
29
  spec.add_development_dependency('bundler', '~> 2.1')
28
30
  spec.add_development_dependency('byebug', '>= 0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trifle-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jozef Vaclavik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,6 +96,7 @@ files:
96
96
  - ".rubocop.yml"
97
97
  - ".ruby-version"
98
98
  - ".tool-versions"
99
+ - CHANGELOG.md
99
100
  - Gemfile
100
101
  - Gemfile.lock
101
102
  - LICENSE
@@ -113,10 +114,12 @@ files:
113
114
  - lib/trifle/logger/version.rb
114
115
  - trifle-logger.gemspec
115
116
  homepage: https://trifle.io
116
- licenses: []
117
+ licenses:
118
+ - MIT
117
119
  metadata:
118
120
  homepage_uri: https://trifle.io
119
121
  source_code_uri: https://github.com/trifle-io/trifle-logger
122
+ changelog_uri: https://github.com/trifle-io/trifle-logger/blob/main/CHANGELOG.md
120
123
  post_install_message:
121
124
  rdoc_options: []
122
125
  require_paths: