klogger-logger 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/VERSION +1 -1
- data/lib/klogger/logger.rb +13 -7
- data/lib/klogger/tagged_logger.rb +56 -0
- data/lib/klogger.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fd4a128b55717b068300e71272284d05eaefa3ed32b28955236679a41fa02e
|
4
|
+
data.tar.gz: c09a76bd59fabc13754f4af45c74373c17dfe19efe17fe2d59b99dff965d770c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f03fe8c99955e64c347d905e0f9225df67706a3c72cfb596b5bf1949234b139f1e56a0b86d849a6b31d6b2b295dd748c2f39feebb0875a2df4940ef6426faeea
|
7
|
+
data.tar.gz: 3f913bd3e2980d04045e1bc001ea1ecb214f9b5d55066f33c5423ae11b5a8180a7a8bbd0bea9c72d781f48dca4a32e7366f4a80bc837ee77c283825b0724e648
|
data/README.md
CHANGED
@@ -135,7 +135,7 @@ Klogger.group(ip: '1.2.3.4') do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
# If you can't use a block you can manually open and close a group but you'll need to be sure to close it
|
138
|
-
#
|
138
|
+
# when you're finished.
|
139
139
|
group_id = Klogger.global_groups.add(ip: '1.2.3.4')
|
140
140
|
# ... do anything that you want - everything will be tagged as appropriate
|
141
141
|
Klogger.global_groups.pop
|
@@ -149,6 +149,16 @@ logger.tagged(name: 'steve') do
|
|
149
149
|
end
|
150
150
|
```
|
151
151
|
|
152
|
+
### Tagged Loggers
|
153
|
+
|
154
|
+
If you wish to apply tags to a series of log entries but you don't wish to use blocks, you can create a "sub" logger which will always include those tags for all messages sent to it.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
logger = Klogger.new(:logger)
|
158
|
+
tagged_logger = logger.create_tagged_logger(tag: 'my-tag')
|
159
|
+
tagged_logger.info "Hello world!" # => will be tagged with tag=my-tag
|
160
|
+
```
|
161
|
+
|
152
162
|
### Silencing
|
153
163
|
|
154
164
|
Sometimes you don't want to log for a little while. You can use the `silence` method to temporarily disable logging.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/lib/klogger/logger.rb
CHANGED
@@ -25,7 +25,11 @@ module Klogger
|
|
25
25
|
go: Formatters::Go
|
26
26
|
}.freeze
|
27
27
|
|
28
|
-
def initialize(name = nil,
|
28
|
+
def initialize(name = nil,
|
29
|
+
destination: $stdout,
|
30
|
+
formatter: :go,
|
31
|
+
highlight: false,
|
32
|
+
include_group_ids: false,
|
29
33
|
tags: {})
|
30
34
|
@name = name
|
31
35
|
@tags = tags
|
@@ -39,12 +43,10 @@ module Klogger
|
|
39
43
|
|
40
44
|
def exception(exception, message = nil, **tags)
|
41
45
|
error(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
backtrace: exception.backtrace[0, 4].join("\n")
|
47
|
-
}.merge(tags)
|
46
|
+
message: message,
|
47
|
+
exception: exception.class.name,
|
48
|
+
exception_message: exception.message,
|
49
|
+
backtrace: exception.backtrace[0, 4].join("\n"), **tags
|
48
50
|
)
|
49
51
|
end
|
50
52
|
|
@@ -96,6 +98,10 @@ module Klogger
|
|
96
98
|
@destinations.delete(destination)
|
97
99
|
end
|
98
100
|
|
101
|
+
def create_tagged_logger(**tags)
|
102
|
+
TaggedLogger.new(self, **tags)
|
103
|
+
end
|
104
|
+
|
99
105
|
private
|
100
106
|
|
101
107
|
def add(severity, message = nil, progname = nil, **tags, &block)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'klogger/logger'
|
4
|
+
|
5
|
+
module Klogger
|
6
|
+
class TaggedLogger
|
7
|
+
|
8
|
+
def initialize(parent, **tags)
|
9
|
+
@parent = parent
|
10
|
+
@tags = tags
|
11
|
+
end
|
12
|
+
|
13
|
+
Klogger::Logger::LEVELS.each do |level|
|
14
|
+
define_method(level) do |message = nil, progname = nil, **tags, &block|
|
15
|
+
@parent.public_send(level, message, progname, **@tags.merge(tags), &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def exception(exception, message = nil, **tags)
|
20
|
+
@parent.exception(exception, message, **@tags.merge(tags))
|
21
|
+
end
|
22
|
+
|
23
|
+
def group(**tags, &block)
|
24
|
+
@parent.group(**@tags.merge(tags), &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_group(**tags)
|
28
|
+
@parent.add_group(**@tags.merge(tags))
|
29
|
+
end
|
30
|
+
|
31
|
+
def pop_group
|
32
|
+
@parent.pop_group
|
33
|
+
end
|
34
|
+
|
35
|
+
def tagged(**tags, &block)
|
36
|
+
@parent.tagged(**@tags.merge(tags), &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def silence!(&block)
|
40
|
+
@parent.silence!(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def unsilence!(&block)
|
44
|
+
@parent.unsilence!(&block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def silenced?
|
48
|
+
@parent.silenced?
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_tagged_logger(**tags)
|
52
|
+
@parent.create_tagged_logger(**@tags.merge(tags))
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/klogger.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klogger-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/klogger/group_set.rb
|
85
85
|
- lib/klogger/json_highlighter.rb
|
86
86
|
- lib/klogger/logger.rb
|
87
|
+
- lib/klogger/tagged_logger.rb
|
87
88
|
- lib/klogger/version.rb
|
88
89
|
homepage: https://github.com/krystal/klogger
|
89
90
|
licenses:
|