testa_logger 0.1.5 → 0.1.8
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 +4 -4
- data/Gemfile.lock +1 -3
- data/lib/testa_logger/logger/options.rb +77 -0
- data/lib/testa_logger/logger/persistence.rb +6 -8
- data/lib/testa_logger/logger.rb +31 -43
- data/lib/testa_logger/version.rb +1 -1
- data/lib/testa_logger.rb +0 -1
- data/logger.iml +5 -6
- data/testa_logger.gemspec +0 -1
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aeafbb6d208450aaa8ae47800cd5eaf737cbd4f4624e1a2e2dbc60561b3b60b
|
4
|
+
data.tar.gz: 5969f0f76d013f6ca9605c439799585acb7adbcd958474d1bb12293f4df93b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f0e83d0707835a7a0888f7ea8c98504fadac2e5d15ee6ce3d85ac955bdf74a966cfafe955daa1ebe12abfbe1395cc7328b5603989b0a9e7e042b5c7487baa9
|
7
|
+
data.tar.gz: 2de76c7dd869c209150f84da3d9bf702ad5f4cfc68939b71c88af632987ac78e36413df95c810481c07d47f81dce059c07ab65902802809661b0d802cbf41f7a
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
testa_logger (0.1.
|
4
|
+
testa_logger (0.1.8)
|
5
5
|
activesupport
|
6
6
|
awesome_print
|
7
7
|
aws-sdk-s3
|
8
8
|
concurrent-ruby
|
9
9
|
json
|
10
|
-
ostruct
|
11
10
|
securerandom
|
12
11
|
|
13
12
|
GEM
|
@@ -43,7 +42,6 @@ GEM
|
|
43
42
|
jmespath (1.6.1)
|
44
43
|
json (2.6.2)
|
45
44
|
minitest (5.16.2)
|
46
|
-
ostruct (0.5.5)
|
47
45
|
parallel (1.22.1)
|
48
46
|
parser (3.1.2.1)
|
49
47
|
ast (~> 2.4.1)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module TestaLogger
|
2
|
+
class Logger
|
3
|
+
class Options
|
4
|
+
|
5
|
+
# @return [String,Integer]
|
6
|
+
attr_accessor :shift_age
|
7
|
+
|
8
|
+
# @return [Integer]
|
9
|
+
attr_accessor :level, :tag_length
|
10
|
+
|
11
|
+
# @return [Proc]
|
12
|
+
attr_accessor :formatter
|
13
|
+
|
14
|
+
# @return [TrueClass, FalseClass]
|
15
|
+
attr_accessor :live, :persist
|
16
|
+
|
17
|
+
# @return [String, nil]
|
18
|
+
attr_accessor :filepath
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :faye_url, :faye_token
|
22
|
+
|
23
|
+
# @return [Hash]
|
24
|
+
attr_accessor :s3_credentials
|
25
|
+
|
26
|
+
def initialize(app, group, subgroup, options)
|
27
|
+
app_and_groups = format_app_and_groups(app, group, subgroup)
|
28
|
+
@shift_age = "daily"
|
29
|
+
@level = DEBUG
|
30
|
+
@formatter = proc do |severity, datetime, _, msg|
|
31
|
+
"#{app_and_groups}[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{format('%-5.5s', severity)} -- : #{msg}\n"
|
32
|
+
end
|
33
|
+
@live = false
|
34
|
+
@filepath = nil
|
35
|
+
@tag_length = 13
|
36
|
+
@persist = true # requires aws credentials set in env variables
|
37
|
+
@faye_url = ENV["WEB_SOCKET_URL"]
|
38
|
+
@faye_token = ENV["FAYE_TOKEN"]
|
39
|
+
@s3_credentials = {
|
40
|
+
region: ENV["AWS_REGION"],
|
41
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
42
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
|
43
|
+
bucket_name: ENV["S3_BUCKET_NAME"],
|
44
|
+
}
|
45
|
+
|
46
|
+
handle_user_options(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_app_and_groups(app, group, subgroup)
|
50
|
+
string = "[ #{app} | #{group} "
|
51
|
+
if subgroup.nil?
|
52
|
+
string += "]"
|
53
|
+
else
|
54
|
+
string += "| #{subgroup} ]"
|
55
|
+
end
|
56
|
+
string
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle_user_options(options)
|
60
|
+
options.deep_symbolize_keys!
|
61
|
+
@shift_age = options[:shift_age] unless options[:shift_age].nil?
|
62
|
+
unless options[:level].nil?
|
63
|
+
options[:level] = SEV_LABEL.index(options[:level].to_s.upcase).to_i unless options[:level].is_a?(Integer)
|
64
|
+
@level = options[:level]
|
65
|
+
end
|
66
|
+
@formatter = options[:formatter] unless options[:formatter].nil?
|
67
|
+
@live = options[:live] unless options[:live].nil?
|
68
|
+
@filepath = File.expand_path(options[:filepath]) unless options[:filepath].nil?
|
69
|
+
@tag_length = options[:tag_length] unless options[:tag_length].nil?
|
70
|
+
@persist = options[:persist] unless options[:persist].nil?
|
71
|
+
@faye_url = options[:faye_url] unless options[:faye_url].nil?
|
72
|
+
@faye_token = options[:faye_token] unless options[:faye_token].nil?
|
73
|
+
@s3_credentials = options[:s3_credentials].deep_symbolize_keys if options[:s3_credentials].present?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module TestaLogger
|
2
2
|
class Logger
|
3
3
|
module Persistence
|
4
|
-
def self.extended(base)
|
5
|
-
require "aws-sdk-s3"
|
6
|
-
base.init_s3_client
|
7
|
-
end
|
8
|
-
|
9
4
|
def init_s3_client
|
5
|
+
require "aws-sdk-s3"
|
10
6
|
Aws.config.update(
|
11
|
-
region: options.
|
12
|
-
credentials: Aws::Credentials.new(
|
7
|
+
region: options.s3_credentials[:region],
|
8
|
+
credentials: Aws::Credentials.new(
|
9
|
+
options.s3_credentials[:access_key_id],
|
10
|
+
options.s3_credentials[:secret_access_key])
|
13
11
|
)
|
14
12
|
@s3 = Aws::S3::Client.new
|
15
13
|
at_exit { persist rescue false }
|
@@ -47,7 +45,7 @@ module TestaLogger
|
|
47
45
|
|
48
46
|
# stop writing into log file with it is being attached, otherwise checksum integrity will fail.
|
49
47
|
response = @s3.put_object(
|
50
|
-
bucket: options.
|
48
|
+
bucket: options.s3_credentials[:bucket_name],
|
51
49
|
key: key,
|
52
50
|
body: IO.read(options.filepath)
|
53
51
|
)
|
data/lib/testa_logger/logger.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require_relative "logger/persistence"
|
2
2
|
require_relative "logger/dispatcher"
|
3
|
+
require_relative "logger/options"
|
3
4
|
|
4
5
|
module TestaLogger
|
6
|
+
# noinspection RubyTooManyMethodsInspection
|
5
7
|
class Logger
|
8
|
+
include Persistence
|
9
|
+
|
6
10
|
TAG = "TestaLogger"
|
7
11
|
|
8
12
|
# @return [String]
|
9
13
|
attr_accessor :app, :group, :subgroup
|
10
14
|
|
11
|
-
# @return [
|
15
|
+
# @return [Options]
|
12
16
|
attr_accessor :options
|
13
17
|
|
14
18
|
# @return [Thread]
|
@@ -27,33 +31,17 @@ module TestaLogger
|
|
27
31
|
# An unknown message that should always be logged.
|
28
32
|
UNKNOWN = 5
|
29
33
|
|
34
|
+
NO_TAG = "NO-TAG"
|
35
|
+
|
30
36
|
def initialize(app, group, subgroup = nil, options = {})
|
31
37
|
@app = app
|
32
38
|
@group = group
|
33
39
|
@subgroup = subgroup
|
34
|
-
|
40
|
+
@options = Options.new(app, group, subgroup, options)
|
35
41
|
create_log_file
|
36
42
|
setup_dispatcher
|
37
43
|
start_write_thread
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def handle_options(options)
|
42
|
-
options.deep_symbolize_keys!
|
43
|
-
@options = Logger.default_options
|
44
|
-
@options.shift_age = options[:shift_age] unless options[:shift_age].nil?
|
45
|
-
unless options[:level].nil?
|
46
|
-
options[:level] = SEV_LABEL.index(options[:level].to_s.upcase).to_i unless options[:level].is_a?(Integer)
|
47
|
-
@options.level = options[:level]
|
48
|
-
end
|
49
|
-
@options.formatter = options[:formatter] unless options[:formatter].nil?
|
50
|
-
@options.live = options[:live] unless options[:live].nil?
|
51
|
-
@options.filepath = File.expand_path(options[:filepath]) unless options[:filepath].nil?
|
52
|
-
@options.tag_length = options[:tag_length] unless options[:tag_length].nil?
|
53
|
-
@options.persist = options[:persist] unless options[:persist].nil?
|
54
|
-
@options.faye_url = options[:faye_url] unless options[:faye_url].nil?
|
55
|
-
@options.faye_token = options[:faye_token] unless options[:faye_token].nil?
|
56
|
-
@options.s3_creds = options[:s3_creds].deep_symbolize_keys unless options[:s3_creds].blank?
|
44
|
+
init_s3_client if @options.persist
|
57
45
|
end
|
58
46
|
|
59
47
|
def create_log_file
|
@@ -90,33 +78,33 @@ module TestaLogger
|
|
90
78
|
end
|
91
79
|
end
|
92
80
|
|
93
|
-
def debug(tag, *args, &block)
|
81
|
+
def debug(tag = NO_TAG, *args, &block)
|
94
82
|
add_log_to_queue(DEBUG, tag, args, &block)
|
95
83
|
end
|
96
84
|
|
97
|
-
def info(tag, *args, &block)
|
85
|
+
def info(tag = NO_TAG, *args, &block)
|
98
86
|
add_log_to_queue(INFO, tag, args, &block)
|
99
87
|
end
|
100
88
|
|
101
|
-
def warn(tag, *args, &block)
|
89
|
+
def warn(tag = NO_TAG, *args, &block)
|
102
90
|
add_log_to_queue(WARN, tag, args, &block)
|
103
91
|
end
|
104
92
|
|
105
|
-
def error(tag, *args, &block)
|
93
|
+
def error(tag = NO_TAG, *args, &block)
|
106
94
|
add_log_to_queue(ERROR, tag, args, &block)
|
107
95
|
end
|
108
96
|
|
109
|
-
def fatal(tag, *args, &block)
|
97
|
+
def fatal(tag = NO_TAG, *args, &block)
|
110
98
|
add_log_to_queue(FATAL, tag, args, &block)
|
111
99
|
end
|
112
100
|
|
113
|
-
def unknown(tag, *args, &block)
|
101
|
+
def unknown(tag = NO_TAG, *args, &block)
|
114
102
|
add_log_to_queue(UNKNOWN, tag, args, &block)
|
115
103
|
end
|
116
104
|
|
117
105
|
def level=(severity)
|
118
106
|
if severity.is_a?(Integer)
|
119
|
-
|
107
|
+
options.level = severity
|
120
108
|
else
|
121
109
|
SEV_LABEL.index(severity.to_s.downcase.upcase).to_i
|
122
110
|
end
|
@@ -209,12 +197,6 @@ module TestaLogger
|
|
209
197
|
}
|
210
198
|
)
|
211
199
|
end
|
212
|
-
|
213
|
-
def default_formatter
|
214
|
-
proc do |severity, datetime, _, msg|
|
215
|
-
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{format('%-5.5s', severity)} -- : #{msg}\n"
|
216
|
-
end
|
217
|
-
end
|
218
200
|
end
|
219
201
|
|
220
202
|
private
|
@@ -223,6 +205,7 @@ module TestaLogger
|
|
223
205
|
return if level < options.level
|
224
206
|
|
225
207
|
time = Time.now
|
208
|
+
tag = extract_tag(tag, args)
|
226
209
|
text = create_log_string(tag, args, &block)
|
227
210
|
formatted_severity = format_severity(level)
|
228
211
|
formatted_text = format_message(formatted_severity, time, "", text)
|
@@ -231,16 +214,21 @@ module TestaLogger
|
|
231
214
|
@dispatcher.push(level, time, tag, formatted_text) if options.live
|
232
215
|
end
|
233
216
|
|
234
|
-
|
217
|
+
# rails and other applications do not use tags,
|
218
|
+
# therefore, if only 1 argument is provided, that means that the message is in the tag variable
|
219
|
+
# then args array is empty.
|
220
|
+
def extract_tag(tag, args)
|
235
221
|
if args.count.zero?
|
236
|
-
if
|
237
|
-
|
238
|
-
|
239
|
-
"[#{padded_tag(tag)}]: #{args_to_string(block.call)}"
|
240
|
-
end
|
241
|
-
else
|
242
|
-
"[#{padded_tag(tag)}]: #{args_to_string(args)}"
|
222
|
+
# if no additional arguments is given, message is in tag variable
|
223
|
+
tag = NO_TAG
|
224
|
+
args.unshift(tag)
|
243
225
|
end
|
226
|
+
tag
|
227
|
+
end
|
228
|
+
|
229
|
+
def create_log_string(tag, args, &block)
|
230
|
+
args.push(block.call) if block
|
231
|
+
"[#{padded_tag(tag)}]: #{args_to_string(args.compact)}"
|
244
232
|
end
|
245
233
|
|
246
234
|
def padded_tag(tag)
|
@@ -253,7 +241,7 @@ module TestaLogger
|
|
253
241
|
if arg.instance_of?(String)
|
254
242
|
arg
|
255
243
|
else
|
256
|
-
arg.ai(limit: 1000, plain:
|
244
|
+
arg.ai(limit: 1000, plain: false)
|
257
245
|
end
|
258
246
|
end.join("\n")
|
259
247
|
end
|
data/lib/testa_logger/version.rb
CHANGED
data/lib/testa_logger.rb
CHANGED
data/logger.iml
CHANGED
@@ -22,7 +22,6 @@
|
|
22
22
|
<orderEntry type="library" scope="PROVIDED" name="jmespath (v1.6.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
23
23
|
<orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
24
24
|
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.16.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="ostruct (v0.5.5, RVM: ruby-2.7.6) [gem]" level="application" />
|
26
25
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
27
26
|
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
28
27
|
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
@@ -43,21 +42,21 @@
|
|
43
42
|
<option name="myRootTask">
|
44
43
|
<RakeTaskImpl id="rake">
|
45
44
|
<subtasks>
|
46
|
-
<RakeTaskImpl description="Build testa_logger-0.1.
|
45
|
+
<RakeTaskImpl description="Build testa_logger-0.1.6.gem into the pkg directory" fullCommand="build" id="build" />
|
47
46
|
<RakeTaskImpl id="build">
|
48
47
|
<subtasks>
|
49
|
-
<RakeTaskImpl description="Generate SHA512 checksum if testa_logger-0.1.
|
48
|
+
<RakeTaskImpl description="Generate SHA512 checksum if testa_logger-0.1.6.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
50
49
|
</subtasks>
|
51
50
|
</RakeTaskImpl>
|
52
51
|
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
53
52
|
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
54
|
-
<RakeTaskImpl description="Build and install testa_logger-0.1.
|
53
|
+
<RakeTaskImpl description="Build and install testa_logger-0.1.6.gem into system gems" fullCommand="install" id="install" />
|
55
54
|
<RakeTaskImpl id="install">
|
56
55
|
<subtasks>
|
57
|
-
<RakeTaskImpl description="Build and install testa_logger-0.1.
|
56
|
+
<RakeTaskImpl description="Build and install testa_logger-0.1.6.gem into system gems without network access" fullCommand="install:local" id="local" />
|
58
57
|
</subtasks>
|
59
58
|
</RakeTaskImpl>
|
60
|
-
<RakeTaskImpl description="Create tag v0.1.
|
59
|
+
<RakeTaskImpl description="Create tag v0.1.6 and build and push testa_logger-0.1.6.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
61
60
|
<RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
|
62
61
|
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
63
62
|
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
data/testa_logger.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "aws-sdk-s3"
|
24
24
|
spec.add_runtime_dependency "concurrent-ruby"
|
25
25
|
spec.add_runtime_dependency "json"
|
26
|
-
spec.add_runtime_dependency "ostruct"
|
27
26
|
spec.add_runtime_dependency "securerandom"
|
28
27
|
|
29
28
|
# Specify which files should be added to the gem when it is released.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testa_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- karlo.razumovic
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: ostruct
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: securerandom
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +118,7 @@ files:
|
|
132
118
|
- lib/testa_logger/log_device/period.rb
|
133
119
|
- lib/testa_logger/logger.rb
|
134
120
|
- lib/testa_logger/logger/dispatcher.rb
|
121
|
+
- lib/testa_logger/logger/options.rb
|
135
122
|
- lib/testa_logger/logger/persistence.rb
|
136
123
|
- lib/testa_logger/version.rb
|
137
124
|
- logger.iml
|