vigilant-ruby 0.0.4 → 0.0.6
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.md +57 -1
- data/lib/vigilant-ruby/logger.rb +10 -4
- data/lib/vigilant-ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f7f1ed256105eb26d3eca1221963c0cb0db06d2fab56630059fc3fc7d064e34
|
4
|
+
data.tar.gz: ff68b2953e375a0e9e741914aca017b614b689870ba4e728e8d153d496c8e38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 931ce0b4a70c782502d0771cf967517d8cc58556f2a69b0fc9a65195f7065f22df5cbcdf538fd5f568a24f2f2625b5fd3bac75f2a181585ceec8f06ee037c4f2
|
7
|
+
data.tar.gz: f7bf06387f135895cc032b9af406bf5ef2b19d3fc41796d8a2ddbb563fa4f55cfcc570faa489f55c524c7a20e1807919b0c11e60feef4431d502a061b2f279ce
|
data/README.md
CHANGED
@@ -1,3 +1,59 @@
|
|
1
1
|
# Vigilant Ruby SDK
|
2
2
|
|
3
|
-
This is the Ruby SDK for Vigilant (https://vigilant.run).
|
3
|
+
This is the Ruby SDK for Vigilant (https://vigilant.run).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install vigilant-ruby
|
9
|
+
```
|
10
|
+
|
11
|
+
## Logging Usage (Standard)
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'vigilant-ruby'
|
15
|
+
|
16
|
+
# Initialize the logger
|
17
|
+
logger = Vigilant::Logger.new(
|
18
|
+
name: 'test-app',
|
19
|
+
endpoint: "ingress.vigilant.run",
|
20
|
+
token: "tk_0000000000000000",
|
21
|
+
)
|
22
|
+
|
23
|
+
# Basic logging
|
24
|
+
logger.info('User logged in')
|
25
|
+
logger.warn('Rate limit approaching')
|
26
|
+
logger.error('Database connection failed')
|
27
|
+
logger.debug('Processing request')
|
28
|
+
|
29
|
+
# Logging with attributes
|
30
|
+
logger.info('User logged in', { user_id: 123, ip_address: '192.168.1.1' })
|
31
|
+
|
32
|
+
# Shutdown the logger
|
33
|
+
logger.shutdown
|
34
|
+
```
|
35
|
+
|
36
|
+
## Logging Usage (Autocapture)
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'vigilant-ruby'
|
40
|
+
|
41
|
+
# Initialize the logger
|
42
|
+
logger = Vigilant::Logger.new(
|
43
|
+
name: 'test-app',
|
44
|
+
endpoint: "ingress.vigilant.run",
|
45
|
+
token: "tk_0000000000000000",
|
46
|
+
)
|
47
|
+
|
48
|
+
# Enable autocapture
|
49
|
+
logger.autocapture_enable
|
50
|
+
|
51
|
+
# Log with autocapture
|
52
|
+
puts "A print statement"
|
53
|
+
|
54
|
+
# Log without autocapture
|
55
|
+
logger.info("A regular log")
|
56
|
+
|
57
|
+
# Shutdown the logger
|
58
|
+
logger.shutdown
|
59
|
+
```
|
data/lib/vigilant-ruby/logger.rb
CHANGED
@@ -18,11 +18,13 @@ module Vigilant
|
|
18
18
|
class Logger
|
19
19
|
# Initialize a Vigilant::Logger instance.
|
20
20
|
#
|
21
|
+
# @param name [String] The name of the application.
|
21
22
|
# @param endpoint [String] The base endpoint for the Vigilant API (e.g. "ingress.vigilant.run").
|
22
23
|
# @param token [String] The authentication token for the Vigilant API.
|
23
24
|
# @param insecure [Boolean] Whether to use HTTP instead of HTTPS (optional, defaults to false).
|
24
25
|
# @param passthrough [Boolean] Whether to also print logs to stdout/stderr (optional, defaults to true).
|
25
|
-
def initialize(endpoint:, token:, insecure: false, passthrough: true)
|
26
|
+
def initialize(endpoint:, token:, name: 'test-app', insecure: false, passthrough: true)
|
27
|
+
@name = name
|
26
28
|
@token = token
|
27
29
|
|
28
30
|
protocol = insecure ? 'http://' : 'https://'
|
@@ -92,7 +94,7 @@ module Vigilant
|
|
92
94
|
|
93
95
|
# Shuts down the logger, flushing any pending logs.
|
94
96
|
def shutdown
|
95
|
-
flush_if_needed(true)
|
97
|
+
flush_if_needed(force: true)
|
96
98
|
@mutex.synchronize { @shutdown = true }
|
97
99
|
@dispatcher_thread&.join
|
98
100
|
end
|
@@ -106,7 +108,7 @@ module Vigilant
|
|
106
108
|
timestamp: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%9NZ'),
|
107
109
|
body: body.to_s,
|
108
110
|
level: level.to_s,
|
109
|
-
attributes: attributes.transform_values(&:to_s)
|
111
|
+
attributes: internal_attributes.merge(attributes.transform_values(&:to_s))
|
110
112
|
}
|
111
113
|
|
112
114
|
@queue << log_msg
|
@@ -123,7 +125,7 @@ module Vigilant
|
|
123
125
|
flush_if_needed
|
124
126
|
sleep @flush_interval
|
125
127
|
end
|
126
|
-
flush_if_needed(true)
|
128
|
+
flush_if_needed(force: true)
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
@@ -165,6 +167,10 @@ module Vigilant
|
|
165
167
|
|
166
168
|
http.request(request)
|
167
169
|
end
|
170
|
+
|
171
|
+
def internal_attributes
|
172
|
+
{ 'service.name' => @name }
|
173
|
+
end
|
168
174
|
end
|
169
175
|
|
170
176
|
# Interceptor for capturing stdout
|