relaton-logger 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +12 -8
- data/lib/relaton/logger/channels/gh_issue.rb +76 -0
- data/lib/relaton/logger/config.rb +1 -1
- data/lib/relaton/logger/pool.rb +4 -4
- data/lib/relaton/logger/version.rb +1 -1
- data/lib/relaton/logger.rb +1 -0
- 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: 56155023be9761bf409a576e22703b1b2f2cc1ef9ef2290d264c29c7ad875549
|
4
|
+
data.tar.gz: a3cd75358fc69210004a40ad4081e8942db2313a260daf1a0e36754e8b42c273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a868f415f0be67022bb18a4192f031c875cb42be1a698fb8b160d2154b95165cedd3b4417aea2070b3ff514bddd62cba01173a70dfaa157536242f4a589fb36
|
7
|
+
data.tar.gz: 921e56e9526a7f1ad6e3fac4205d042ef21a996ab9c4bbbfd7e6841b5e6ad99bc44a9a3243252e529017809b73249d02ee1f46e32942e42ed91865b1eb93d783
|
data/README.adoc
CHANGED
@@ -48,22 +48,26 @@ Relaton.logger_pool.error("progname", key: "KEY") { "message" }
|
|
48
48
|
[progname] ERROR: (KEY) message
|
49
49
|
----
|
50
50
|
|
51
|
-
The logger pool can configured to contain multiple loggers.
|
51
|
+
The logger pool can be configured to contain multiple loggers. Initially, there is one `:default` logger. Any instance of loggers in the logger pool are accessible with `[]` method. To add or replace a logger use `[]=` method of the logger pool and pass the logger as an argument. The loggers in the pool are called in the order they are added to the pool.
|
52
52
|
|
53
53
|
[source, ruby]
|
54
54
|
----
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
# Access logger
|
56
|
+
Relaton.logger_pool[:default]
|
57
|
+
=>
|
58
|
+
#<Relaton::Logger::Log:0x00000001212068c8
|
59
|
+
|
60
|
+
# Add a new logger
|
61
|
+
Relaton.logger_pool[:file] = Relaton::Logger::Log.new("relaton.log", levels: [:info, :warn])
|
58
62
|
----
|
59
63
|
|
60
|
-
To
|
64
|
+
To change the log level of a logger, call the `level=` method of the logger.
|
61
65
|
|
62
66
|
[source, ruby]
|
63
67
|
----
|
64
|
-
Relaton
|
65
|
-
|
66
|
-
|
68
|
+
Relaton.logger_pool[:default].levels = [:info, :warn, :error]
|
69
|
+
Relaton.logger_pool[:default].add_level :fatal
|
70
|
+
Relaton.logger_pool[:default].remove_level :warn
|
67
71
|
----
|
68
72
|
|
69
73
|
To create a new logger, call the `new` method of the `Relaton::Logger::Log` class and pass arguments:
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Relaton
|
4
|
+
module Logger
|
5
|
+
module Channels
|
6
|
+
#
|
7
|
+
# This class is used to create a GitHub issue with the log content.
|
8
|
+
# The issue will be created in the repository specified in the
|
9
|
+
# initializer.
|
10
|
+
# The log content is stored in the issue body. Only unique log messages
|
11
|
+
# are stored.
|
12
|
+
# Token is required to create an issue. It should be stored in the
|
13
|
+
# environment variable GITHUB_TOKEN.
|
14
|
+
# To create an issue, call the create_issue method after all log messages
|
15
|
+
# are written.
|
16
|
+
#
|
17
|
+
class GhIssue
|
18
|
+
#
|
19
|
+
# Create a new instance of the class.
|
20
|
+
#
|
21
|
+
# @param [String] repo owner/repo name
|
22
|
+
# @param [String] title title of the issue
|
23
|
+
#
|
24
|
+
def initialize(repo, title)
|
25
|
+
@repo = repo
|
26
|
+
@title = title
|
27
|
+
@log = Set.new
|
28
|
+
puts "GITHUB_TOKEN is not set!" if ENV["GITHUB_TOKEN"].nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def write(string)
|
32
|
+
@log << string
|
33
|
+
end
|
34
|
+
|
35
|
+
def close
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_issue
|
39
|
+
return if @log.empty? || ENV["GITHUB_TOKEN"].nil?
|
40
|
+
|
41
|
+
responce = post_issue
|
42
|
+
|
43
|
+
if responce.code.to_i == 201
|
44
|
+
puts "Issue created!"
|
45
|
+
else
|
46
|
+
puts "Failed to create issue: #{responce.code} #{responce.message}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def post_issue
|
53
|
+
uri = URI("https://api.github.com/repos/#{@repo}/issues")
|
54
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
55
|
+
http.use_ssl = true
|
56
|
+
|
57
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
58
|
+
request.body = issue_body.to_json
|
59
|
+
|
60
|
+
http.request(request)
|
61
|
+
end
|
62
|
+
|
63
|
+
def issue_body
|
64
|
+
{ title: @title, body: @log.join("\n") }
|
65
|
+
end
|
66
|
+
|
67
|
+
def headers
|
68
|
+
{
|
69
|
+
"Content-Type" => "application/json",
|
70
|
+
"Authorization" => "token #{ENV['GITHUB_TOKEN']}",
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/relaton/logger/pool.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module Relaton::Logger
|
2
2
|
class Pool
|
3
3
|
extend Forwardable
|
4
|
-
def_delegators :@loggers,
|
4
|
+
def_delegators :@loggers, :[], :[]=, :size, :each
|
5
5
|
|
6
6
|
attr_accessor :loggers
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@loggers =
|
9
|
+
@loggers = {}
|
10
10
|
end
|
11
11
|
|
12
12
|
def unknown(message = nil, progname = nil, **args, &block)
|
13
|
-
@loggers.each { |logger| logger.send(__callee__, message, progname, **args, &block) }
|
13
|
+
@loggers.each { |_, logger| logger.send(__callee__, message, progname, **args, &block) }
|
14
14
|
nil
|
15
15
|
end
|
16
16
|
|
17
17
|
%i[fatal error warn info debug].each { |m| alias_method m, :unknown }
|
18
18
|
|
19
19
|
def truncate
|
20
|
-
@loggers.each
|
20
|
+
@loggers.each { |_, logger| logger.truncate }
|
21
21
|
nil
|
22
22
|
end
|
23
23
|
end
|
data/lib/relaton/logger.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- README.adoc
|
38
38
|
- Rakefile
|
39
39
|
- lib/relaton/logger.rb
|
40
|
+
- lib/relaton/logger/channels/gh_issue.rb
|
40
41
|
- lib/relaton/logger/config.rb
|
41
42
|
- lib/relaton/logger/formatter_json.rb
|
42
43
|
- lib/relaton/logger/formatter_string.rb
|
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
67
|
- !ruby/object:Gem::Version
|
67
68
|
version: '0'
|
68
69
|
requirements: []
|
69
|
-
rubygems_version: 3.3.
|
70
|
+
rubygems_version: 3.3.27
|
70
71
|
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: The logger for Relaton gem.
|