lokilogger 0.5.0 → 1.0.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 +4 -4
- data/README.adoc +4 -3
- data/lib/lokilogger/client.rb +1 -3
- data/lib/lokilogger/formatter.rb +36 -0
- data/lib/lokilogger/severity.rb +31 -0
- data/lib/lokilogger/version.rb +1 -1
- data/lib/lokilogger.rb +88 -54
- data/lokilogger.gemspec +0 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 013c3df35dc258985f0bce263e8b891e77248458501166742e48323faf31a920
|
4
|
+
data.tar.gz: d333983151ff4524daedfdc1a5f7a94b6e25e427786dcf1103fba5113ce3adca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61907a403d311da65316452abf1beba6cc12fd8e98bf9283a576551b696972a42dd2496f77671f2d9491802269ad36153ff2f8fc894e375f505e9aa175847763
|
7
|
+
data.tar.gz: 4e392ebaf36816ce9442e6e1fa58b2fcadf68053280e79c0275b58daf89d0786b582a36371705595d19a5579ceaff99b3581583675ff005fdc465e24bcbc9914
|
data/README.adoc
CHANGED
@@ -59,14 +59,15 @@ Start by creating a new logger instance:
|
|
59
59
|
|
60
60
|
[source,ruby]
|
61
61
|
----
|
62
|
-
#
|
63
|
-
|
62
|
+
# required: url, log_level, version and tags
|
63
|
+
# optional: username and password (if one of them is nil, no auth will be used)
|
64
|
+
logger = Lokilogger::Logger.new({url:, log_level: 0, version: "v1", username:, password:, tags: {foo: "bar"}})
|
64
65
|
----
|
65
66
|
|
66
67
|
If you need proxy or custom TLS settings, you can optionally pass as well:
|
67
68
|
|
68
69
|
- ssl_options (link:https://lostisland.github.io/faraday/#/customization/ssl-options[Faraday docs on ssl options])
|
69
|
-
- proxy_options (link:https://lostisland.github.io/faraday/#/customization/proxy-options[
|
70
|
+
- proxy_options (link:https://lostisland.github.io/faraday/#/customization/proxy-options[Faraday docs on proxy options])
|
70
71
|
|
71
72
|
then it's straight forward:
|
72
73
|
|
data/lib/lokilogger/client.rb
CHANGED
@@ -17,15 +17,13 @@ module Lokilogger
|
|
17
17
|
|
18
18
|
Faraday.default_adapter = :async_http
|
19
19
|
@conn = Faraday.new url: @config[:url], headers: {"Content-Type" => "application/json"}, ssl: ssl_options, proxy: proxy_options, request: request_options do |builder|
|
20
|
-
builder.request :authorization, :basic, @config[:username], @config[:password]
|
20
|
+
builder.request :authorization, :basic, @config[:username], @config[:password] if @config[:username] && @config[:password]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def check_config
|
25
25
|
fail ConfigError, "missing/malformed url in config" if !@config[:url] || @config[:url] !~ %r{^(http|https)://}
|
26
26
|
fail ConfigError, "missing version in config" unless @config[:version]
|
27
|
-
fail ConfigError, "missing auth username in config" unless @config[:username]
|
28
|
-
fail ConfigError, "missing auth password in config" unless @config[:password]
|
29
27
|
fail ConfigError, "missing tags in config" unless @config[:tags]
|
30
28
|
fail ConfigError, "missing log_level in config" unless @config[:log_level]
|
31
29
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokilogger
|
4
|
+
# Default formatter for log messages.
|
5
|
+
class Formatter
|
6
|
+
Format = "%.1s, [%s #%d] %5s -- %s: %s\n"
|
7
|
+
DatetimeFormat = "%Y-%m-%dT%H:%M:%S.%6N"
|
8
|
+
|
9
|
+
attr_accessor :datetime_format
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@datetime_format = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def call severity, time, progname, msg
|
16
|
+
format Format, severity, format_datetime(time), Process.pid, severity, progname, msg2str(msg)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def format_datetime time
|
22
|
+
time.strftime(@datetime_format || DatetimeFormat)
|
23
|
+
end
|
24
|
+
|
25
|
+
def msg2str msg
|
26
|
+
case msg
|
27
|
+
when ::String
|
28
|
+
msg
|
29
|
+
when ::Exception
|
30
|
+
"#{msg.message} (#{msg.class})\n#{msg.backtrace.join "\n" if msg.backtrace}"
|
31
|
+
else
|
32
|
+
msg.inspect
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokilogger
|
4
|
+
# Logging severity.
|
5
|
+
module Severity
|
6
|
+
# Low-level information, mostly for developers.
|
7
|
+
DEBUG = 0
|
8
|
+
# Generic (useful) information about system operation.
|
9
|
+
INFO = 1
|
10
|
+
# A warning.
|
11
|
+
WARN = 2
|
12
|
+
# A handleable error condition.
|
13
|
+
ERROR = 3
|
14
|
+
# An unhandleable error that results in a program crash.
|
15
|
+
FATAL = 4
|
16
|
+
# An unknown message that should always be logged.
|
17
|
+
UNKNOWN = 5
|
18
|
+
|
19
|
+
LEVELS = {"debug" => DEBUG, "info" => INFO, "warn" => WARN, "error" => ERROR, "fatal" => FATAL, "unknown" => UNKNOWN}.freeze
|
20
|
+
private_constant :LEVELS
|
21
|
+
|
22
|
+
def self.coerce severity
|
23
|
+
if severity.is_a? Integer
|
24
|
+
severity
|
25
|
+
else
|
26
|
+
key = severity.to_s.downcase
|
27
|
+
LEVELS[key] || fail(ArgumentError, "invalid log level: #{severity}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/lokilogger/version.rb
CHANGED
data/lib/lokilogger.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "lokilogger/formatter"
|
4
|
+
require "lokilogger/severity"
|
3
5
|
require "zeitwerk"
|
4
6
|
|
5
7
|
Zeitwerk::Loader.new.then do |loader|
|
@@ -14,77 +16,109 @@ module Lokilogger
|
|
14
16
|
@loader ||= registry.loaders.find { |loader| loader.tag == File.basename(__FILE__, ".rb") }
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
self
|
20
|
-
end
|
19
|
+
class Logger
|
20
|
+
include Severity
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def initialize config
|
23
|
+
@client = Lokilogger::Client.new config
|
24
|
+
@default_formatter = Formatter.new
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def datetime_format= datetime_format
|
28
|
+
@default_formatter.datetime_format = datetime_format
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def datetime_format
|
32
|
+
@default_formatter.datetime_format
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
true
|
36
|
-
end
|
35
|
+
attr_accessor :formatter
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def debug(*args)
|
38
|
+
message "debug", args
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def debug?
|
42
|
+
@client.log_level <= DEBUG
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
def debug!
|
46
|
+
@client.log_level = DEBUG
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
def info(*args)
|
50
|
+
message "info", args
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
def info?
|
54
|
+
@client.log_level <= INFO
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
def info!
|
58
|
+
@client.log_level = INFO
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
def warn(*args)
|
62
|
+
message "warn", args
|
63
|
+
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
def warn?
|
66
|
+
@client.log_level <= WARN
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
def warn!
|
70
|
+
@client.log_level = WARN
|
71
|
+
end
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
def error(*args)
|
74
|
+
message "error", args
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
def error?
|
78
|
+
@client.log_level <= ERROR
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
def error!
|
82
|
+
@client.log_level = ERROR
|
83
|
+
end
|
84
|
+
|
85
|
+
def fatal(*args)
|
86
|
+
message "fatal", args
|
87
|
+
end
|
88
|
+
|
89
|
+
def fatal?
|
90
|
+
@client.log_level <= FATAL
|
91
|
+
end
|
92
|
+
|
93
|
+
def fatal!
|
94
|
+
@client.log_level = FATAL
|
95
|
+
end
|
96
|
+
|
97
|
+
def unknown(*args)
|
98
|
+
message "unknown", args
|
99
|
+
end
|
100
|
+
|
101
|
+
def unknown?
|
102
|
+
@client.log_level <= UNKNOWN
|
103
|
+
end
|
104
|
+
|
105
|
+
def unknown!
|
106
|
+
@client.log_level = UNKNOWN
|
107
|
+
end
|
108
|
+
|
109
|
+
def level= severity
|
110
|
+
@client.log_level = Severity.coerce severity
|
111
|
+
end
|
112
|
+
|
113
|
+
def level
|
114
|
+
@client.log_level
|
115
|
+
end
|
83
116
|
|
84
|
-
|
85
|
-
|
86
|
-
|
117
|
+
def message(severity, *args)
|
118
|
+
message = args[0][0]
|
119
|
+
extra_tags = args[0][1] if args[0].count > 1
|
87
120
|
|
88
|
-
|
121
|
+
@client.request severity, message, extra_tags
|
122
|
+
end
|
89
123
|
end
|
90
124
|
end
|
data/lokilogger.gemspec
CHANGED
@@ -15,9 +15,6 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
spec.metadata = {"label" => "lokilogger", "rubygems_mfa_required" => "true"}
|
17
17
|
|
18
|
-
#spec.signing_key = Gem.default_key_path
|
19
|
-
#spec.cert_chain = [Gem.default_cert_path]
|
20
|
-
|
21
18
|
spec.required_ruby_version = "~> 3.2"
|
22
19
|
spec.add_dependency "async", "~> 2.6", ">= 2.6.5"
|
23
20
|
spec.add_dependency "async-http-faraday", "~> 0.12.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lokilogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nils Bartels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- lib/lokilogger.rb
|
107
107
|
- lib/lokilogger/client.rb
|
108
108
|
- lib/lokilogger/error.rb
|
109
|
+
- lib/lokilogger/formatter.rb
|
110
|
+
- lib/lokilogger/severity.rb
|
109
111
|
- lib/lokilogger/version.rb
|
110
112
|
- lokilogger.gemspec
|
111
113
|
homepage: https://gitlab.com/sukunai/lokilogger
|