lokilogger 0.6.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +2 -2
- 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 +1 -1
- 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: beca007a56461abf51d521051073e9514f30ce6834b9d2a0f1cf10a0016242c9
|
4
|
+
data.tar.gz: 9ffee2c539de6dc7803a93538452e24639f5a2110a33d8c059bdc44e2004c160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65d8d472ead0c1d655acdaf876e65e15e5f3f89c90471a3b4519b975751ddb6b3df1d8c63c6e0964fc228d918397dec10e427722318a227a43b94688129877c
|
7
|
+
data.tar.gz: dc681934d3d5a921bec4631574006d9765d073ac5f3a136641a16d69093881e9e5c7f536cefe8c8236ff1bce888d9f711b0a8fa21c8369d875702974788cba47
|
data/README.adoc
CHANGED
@@ -61,13 +61,13 @@ Start by creating a new logger instance:
|
|
61
61
|
----
|
62
62
|
# required: url, log_level, version and tags
|
63
63
|
# optional: username and password (if one of them is nil, no auth will be used)
|
64
|
-
logger = Lokilogger.new({url:, log_level: 0, version: "v1", username:, password:, tags: {foo: "bar"}})
|
64
|
+
logger = Lokilogger::Logger.new({url:, log_level: 0, version: "v1", username:, password:, tags: {foo: "bar"}})
|
65
65
|
----
|
66
66
|
|
67
67
|
If you need proxy or custom TLS settings, you can optionally pass as well:
|
68
68
|
|
69
69
|
- ssl_options (link:https://lostisland.github.io/faraday/#/customization/ssl-options[Faraday docs on ssl options])
|
70
|
-
- 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])
|
71
71
|
|
72
72
|
then it's straight forward:
|
73
73
|
|
data/lib/lokilogger/client.rb
CHANGED
@@ -17,9 +17,7 @@ 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
|
-
if @config[:username] && @config[:password]
|
21
|
-
builder.request :authorization, :basic, @config[:username], @config[:password]
|
22
|
-
end
|
20
|
+
builder.request :authorization, :basic, @config[:username], @config[:password] if @config[:username] && @config[:password]
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -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
@@ -6,7 +6,7 @@ require "lokilogger/version"
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "lokilogger"
|
9
|
-
spec.version = Lokilogger::
|
9
|
+
spec.version = Lokilogger::Version
|
10
10
|
spec.authors = ["Nils Bartels"]
|
11
11
|
spec.email = ["rubygems@nils.bartels.xyz"]
|
12
12
|
spec.homepage = "https://gitlab.com/sukunai/lokilogger"
|
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:
|
4
|
+
version: 1.1.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
|