trifle-logger 0.1.0 → 0.2.0

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: 7d2deabd47fce1cb9b29ab0eeaad61aa482e437c3c38b6c0387a96a37a3e9287
4
- data.tar.gz: 9e7e5439cabc64584f885145f888d9f021633ce41e0b42c17a8d83f345a7236a
3
+ metadata.gz: a6df3b5ac2c9be39829e661fb9793383abdb61999e3fdec1a749f8127736d9fd
4
+ data.tar.gz: 45645936044b84f02911c731ae346c402ca586368ebe18e1a21705ba5df2bdc7
5
5
  SHA512:
6
- metadata.gz: e7d722da4c38ba4cd06945969eb493fdcb040d80b095e895512d1ab3fe31eaefa26678bd4cd03eb5485a2d3df3f6b76536ae64a69e5c539910c4095feb56093f
7
- data.tar.gz: bfdcb7461e9b069846e5f9abd39ed2e4c8368aa598fdec48e23640f5647e7e7ecd1a9ed92d3d28ad570b7bd1180d023dd343c0605ba7c6872e9977bdc084fd21
6
+ metadata.gz: b38fa3326d9e49f32a0831556775a47df90082837ce5764e5388b2adce820f4b55e198a8660c899662ab3adff503b8434b2253699930a377785a65cced634079
7
+ data.tar.gz: 14e02a5990b21aed720a7ffc348e71d67cc21e1080069628c2299cee2793260ab8afc002d78f4c1557dec8b82561d5c1e8d8fa6554398e4ee76040a404979203
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trifle-logger (0.1.0)
4
+ trifle-logger (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/trifle/logger.rb CHANGED
@@ -56,5 +56,17 @@ module Trifle
56
56
 
57
57
  tracer.fail!
58
58
  end
59
+
60
+ def self.warn!
61
+ return unless tracer
62
+
63
+ tracer.warn!
64
+ end
65
+
66
+ def self.ignore!
67
+ return unless tracer
68
+
69
+ tracer.ignore!
70
+ end
59
71
  end
60
72
  end
@@ -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_klass, :callbacks, :bump_every
7
7
 
8
8
  def initialize
9
9
  @tracer_klass = Trifle::Logger::Tracer::Hash
10
- @callbacks = {
11
- wrapup: []
12
- }
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
@@ -4,7 +4,7 @@ module Trifle
4
4
  module Logger
5
5
  module Tracer
6
6
  class Hash
7
- attr_accessor :key, :meta, :data, :tags, :artifacts, :state
7
+ attr_accessor :key, :meta, :data, :tags, :artifacts, :state, :ignore, :reference
8
8
 
9
9
  def initialize(key:, meta: nil)
10
10
  @key = key
@@ -12,10 +12,12 @@ module Trifle
12
12
  @data = []
13
13
  @tags = []
14
14
  @artifacts = []
15
- @state = :success
15
+ @state = :running
16
+ @ignore = false
16
17
  @result_prefix = '=> '
17
18
 
18
19
  trace("Trifle::Trace has been initialized for #{key}")
20
+ @reference = liftoff.first
19
21
  end
20
22
 
21
23
  def keys
@@ -23,7 +25,7 @@ module Trifle
23
25
  parts.count.times.map { |i| parts[0..i].join('/') }
24
26
  end
25
27
 
26
- def trace(message, state: :success, head: false)
28
+ def trace(message, state: :success, head: false) # rubocop:disable Metrics/MethodLength
27
29
  result = yield if block_given?
28
30
  rescue => e # rubocop:disable Style/RescueStandardError
29
31
  raise e
@@ -33,20 +35,21 @@ module Trifle
33
35
  head: head, state: block_given? && result.nil? || e ? :error : state
34
36
  )
35
37
  dump_result(result) if block_given?
38
+ bump
36
39
  result
37
40
  end
38
41
 
39
42
  def dump_message(message, head:, state:)
40
43
  @data << {
41
44
  at: now, message: message,
42
- state: state, head: head, meta: false
45
+ state: state, head: head, meta: false, media: false
43
46
  }
44
47
  end
45
48
 
46
49
  def dump_result(result)
47
50
  @data << {
48
51
  at: now, message: "#{@result_prefix}#{result.inspect}",
49
- state: :success, head: false, meta: true
52
+ state: :success, head: false, meta: true, media: false
50
53
  }
51
54
  end
52
55
 
@@ -56,25 +59,58 @@ module Trifle
56
59
 
57
60
  def tag(tag)
58
61
  @tags << tag
62
+ bump
63
+ tag
59
64
  end
60
65
 
61
66
  def artifact(name, path)
62
67
  @data << {
63
- at: now, message: "Artifact: #{name}",
64
- state: :success, head: false, meta: true
68
+ at: now, message: name,
69
+ state: :success, head: false, meta: false, media: true
65
70
  }
66
71
  @artifacts << path
72
+ bump
73
+ path
67
74
  end
68
75
 
69
76
  def fail!
70
77
  @state = :error
71
78
  end
72
79
 
80
+ def warn!
81
+ @state = :warning
82
+ end
83
+
84
+ def success!
85
+ @state = :success
86
+ end
87
+
73
88
  def success?
74
89
  @state == :success
75
90
  end
76
91
 
92
+ def running?
93
+ @state == :running
94
+ end
95
+
96
+ def ignore!
97
+ @ignore = true
98
+ end
99
+
100
+ def liftoff
101
+ @bumped_at = now
102
+ Trifle::Logger.default.on_liftoff(self)
103
+ end
104
+
105
+ def bump
106
+ return unless @bumped_at && @bumped_at <= now - Trifle::Logger.default.bump_every
107
+
108
+ @bumped_at = now
109
+ Trifle::Logger.default.on_bump(self)
110
+ end
111
+
77
112
  def wrapup
113
+ success! if running?
78
114
  Trifle::Logger.default.on_wrapup(self)
79
115
  end
80
116
  end
@@ -14,6 +14,14 @@ module Trifle
14
14
 
15
15
  def fail!; end
16
16
 
17
+ def warn!; end
18
+
19
+ def ignore!; end
20
+
21
+ def liftoff; end
22
+
23
+ def bump; end
24
+
17
25
  def wrapup; end
18
26
  end
19
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Logger
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.0
4
+ version: 0.2.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-03-28 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler