trifle-logger 0.1.3 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +16 -17
- data/Gemfile.lock +1 -1
- data/lib/trifle/logger/configuration.rb +16 -5
- data/lib/trifle/logger/tracer/hash.rb +42 -6
- data/lib/trifle/logger/tracer/null.rb +6 -0
- data/lib/trifle/logger/version.rb +1 -1
- data/lib/trifle/logger.rb +6 -0
- data/trifle-logger.gemspec +8 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22b50e2000ee750a8f1d944ac0616112672f0075e2dd083775946c989a7a9262
|
4
|
+
data.tar.gz: f11284203057303f713dfd097cf48cc1bfa4a59169118bd2b80fa9efbe95b9c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd97d0bd9e57ed06448352b30c65a544f49edbdabcabdbfdd1c326e7e46d2904d8adb99c5b8993dd5c743610ba13b1f191a38f408b3fdc1eaf130fa6a0767dc6
|
7
|
+
data.tar.gz: a51b16ea5f6a884db7daea389325a2a316b7594290b8ad16bcb1fcadb8aef943c20c2929931f3d7c074e95de64c29983401e08f3511116c7af60181e9fe5f3c1
|
data/.github/workflows/ruby.yml
CHANGED
@@ -9,29 +9,28 @@ name: Ruby
|
|
9
9
|
|
10
10
|
on:
|
11
11
|
push:
|
12
|
-
branches: [
|
12
|
+
branches: [main]
|
13
13
|
pull_request:
|
14
|
-
branches: [
|
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: [
|
21
|
+
ruby-version: ["3.0"]
|
23
22
|
|
24
23
|
steps:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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/Gemfile.lock
CHANGED
@@ -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
|
-
|
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, []).
|
27
|
+
@callbacks.fetch(:wrapup, []).map do |c|
|
17
28
|
c.call(tracer)
|
18
29
|
end
|
19
30
|
end
|
@@ -4,19 +4,25 @@ 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
|
12
13
|
@data = []
|
13
14
|
@tags = []
|
14
15
|
@artifacts = []
|
15
|
-
@state = :
|
16
|
+
@state = :running
|
16
17
|
@ignore = false
|
17
18
|
@result_prefix = '=> '
|
18
19
|
|
19
|
-
trace("
|
20
|
+
trace("Tracer has been initialized for #{key}")
|
21
|
+
@reference = liftoff.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def config
|
25
|
+
@config || Trifle::Logger.default
|
20
26
|
end
|
21
27
|
|
22
28
|
def keys
|
@@ -24,7 +30,7 @@ module Trifle
|
|
24
30
|
parts.count.times.map { |i| parts[0..i].join('/') }
|
25
31
|
end
|
26
32
|
|
27
|
-
def trace(message, state: :success, head: false)
|
33
|
+
def trace(message, state: :success, head: false) # rubocop:disable Metrics/MethodLength
|
28
34
|
result = yield if block_given?
|
29
35
|
rescue => e # rubocop:disable Style/RescueStandardError
|
30
36
|
raise e
|
@@ -34,6 +40,7 @@ module Trifle
|
|
34
40
|
head: head, state: block_given? && result.nil? || e ? :error : state
|
35
41
|
)
|
36
42
|
dump_result(result) if block_given?
|
43
|
+
bump
|
37
44
|
result
|
38
45
|
end
|
39
46
|
|
@@ -57,6 +64,8 @@ module Trifle
|
|
57
64
|
|
58
65
|
def tag(tag)
|
59
66
|
@tags << tag
|
67
|
+
bump
|
68
|
+
tag
|
60
69
|
end
|
61
70
|
|
62
71
|
def artifact(name, path)
|
@@ -65,22 +74,49 @@ module Trifle
|
|
65
74
|
state: :success, head: false, meta: false, media: true
|
66
75
|
}
|
67
76
|
@artifacts << path
|
77
|
+
bump
|
78
|
+
path
|
68
79
|
end
|
69
80
|
|
70
81
|
def fail!
|
71
82
|
@state = :error
|
72
83
|
end
|
73
84
|
|
85
|
+
def warn!
|
86
|
+
@state = :warning
|
87
|
+
end
|
88
|
+
|
89
|
+
def success!
|
90
|
+
@state = :success
|
91
|
+
end
|
92
|
+
|
74
93
|
def success?
|
75
94
|
@state == :success
|
76
95
|
end
|
77
96
|
|
97
|
+
def running?
|
98
|
+
@state == :running
|
99
|
+
end
|
100
|
+
|
78
101
|
def ignore!
|
79
102
|
@ignore = true
|
80
103
|
end
|
81
104
|
|
105
|
+
def liftoff
|
106
|
+
@bumped_at = now
|
107
|
+
config.on_liftoff(self)
|
108
|
+
end
|
109
|
+
|
110
|
+
def bump
|
111
|
+
return unless @bumped_at && @bumped_at <= now - config.bump_every
|
112
|
+
|
113
|
+
@bumped_at = now
|
114
|
+
config.on_bump(self)
|
115
|
+
end
|
116
|
+
|
82
117
|
def wrapup
|
83
|
-
|
118
|
+
success! if running?
|
119
|
+
config.on_wrapup(self)
|
84
120
|
end
|
85
121
|
end
|
86
122
|
end
|
data/lib/trifle/logger.rb
CHANGED
data/trifle-logger.gemspec
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
require_relative 'lib/trifle/logger/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
4
|
+
spec.name = 'trifle-logger'
|
5
5
|
spec.version = Trifle::Logger::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
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.
|
13
|
+
spec.licenses = ['MIT']
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
|
14
15
|
|
15
|
-
spec.metadata[
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
17
|
spec.metadata['source_code_uri'] = 'https://github.com/trifle-io/trifle-logger'
|
17
18
|
|
18
19
|
# Specify which files should be added to the gem when it is released.
|
@@ -20,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
20
21
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
23
|
end
|
23
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
24
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
26
27
|
|
27
28
|
spec.add_development_dependency('bundler', '~> 2.1')
|
28
29
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jozef Vaclavik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,7 +113,8 @@ files:
|
|
113
113
|
- lib/trifle/logger/version.rb
|
114
114
|
- trifle-logger.gemspec
|
115
115
|
homepage: https://trifle.io
|
116
|
-
licenses:
|
116
|
+
licenses:
|
117
|
+
- MIT
|
117
118
|
metadata:
|
118
119
|
homepage_uri: https://trifle.io
|
119
120
|
source_code_uri: https://github.com/trifle-io/trifle-logger
|