cloudwatchlogger 0.3.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/cloudwatchlogger/client/aws_sdk/threaded.rb +15 -6
- data/lib/cloudwatchlogger/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 132c7aab13981c643838904bd543fd3dadf18e35a46df7aa3cfba528e5732a7a
|
4
|
+
data.tar.gz: 7f64be893d988a05eb5bf4b607261a95f4ff623fe73d13f09e573950b1cf9e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a81c48830dec6cfdb4ab851121f3cce19e2859d9549ac853338575f6e15cdadc1c03d5fa3beda5e04e68f76afdcb5ff3f00efb9ef1a0f65e3a454ec9992b841
|
7
|
+
data.tar.gz: cb7283ed4226ad1deda01e16a4c1578297f6f416f8dc827a76cf8edbaf8e79e389e3af9d32067cd5ed1593f0f0374b70f9e7826fd25863ed12a017bc402f0dff
|
data/README.md
CHANGED
@@ -86,6 +86,18 @@ Will produce the following log message in CloudWatch Logs:
|
|
86
86
|
"<Date> severity=WARN, boom=box, bar=soap"
|
87
87
|
```
|
88
88
|
|
89
|
+
### Custom Log Formatters
|
90
|
+
The default formatter in this gem ensures that the timestamp sent to cloudwatch will reflect the time the message was pushed onto the queue. If you want to use a custom log formatter, in order for you to not have a disparity between your actual log time and the time reflected in CloudWatch, you will need to ensure your formatter is a `Hash` with a key for `message` which will contain your log message, and `epoch_time` which should be an epoch time formatted timestamp for your log entry, like so:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
94
|
+
{
|
95
|
+
message: "CUSTOM FORMATTER PREFIX: #{msg}\n",
|
96
|
+
epoch_time: (datetime.utc.to_f.round(3) * 1000).to_i
|
97
|
+
}
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
89
101
|
Releasing
|
90
102
|
-----
|
91
103
|
|
@@ -57,10 +57,7 @@ module CloudWatchLogger
|
|
57
57
|
event = {
|
58
58
|
log_group_name: @log_group_name,
|
59
59
|
log_stream_name: @log_stream_name,
|
60
|
-
log_events: [
|
61
|
-
timestamp: message_object[:epoch_time],
|
62
|
-
message: message_object[:message]
|
63
|
-
}]
|
60
|
+
log_events: [log_event(message_object)]
|
64
61
|
}
|
65
62
|
event[:sequence_token] = @sequence_token if @sequence_token
|
66
63
|
response = @client.put_log_events(event)
|
@@ -95,7 +92,7 @@ module CloudWatchLogger
|
|
95
92
|
def connect!(opts = {})
|
96
93
|
args = { http_open_timeout: opts[:open_timeout], http_read_timeout: opts[:read_timeout] }
|
97
94
|
args[:region] = @opts[:region] if @opts[:region]
|
98
|
-
args.merge( @credentials.key?(:access_key_id) ? { access_key_id: @credentials[:access_key_id], secret_access_key: @credentials[:secret_access_key] } : {} )
|
95
|
+
args.merge!( @credentials.key?(:access_key_id) ? { access_key_id: @credentials[:access_key_id], secret_access_key: @credentials[:secret_access_key] } : {} )
|
99
96
|
|
100
97
|
@client = Aws::CloudWatchLogs::Client.new(args)
|
101
98
|
begin
|
@@ -108,10 +105,22 @@ module CloudWatchLogger
|
|
108
105
|
log_group_name: @log_group_name
|
109
106
|
)
|
110
107
|
retry
|
111
|
-
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException,
|
108
|
+
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException,
|
112
109
|
Aws::CloudWatchLogs::Errors::AccessDeniedException
|
113
110
|
end
|
114
111
|
end
|
112
|
+
|
113
|
+
def log_event(message_object)
|
114
|
+
timestamp = (Time.now.utc.to_f.round(3) * 1000).to_i
|
115
|
+
message = message_object
|
116
|
+
|
117
|
+
if message_object.is_a?(Hash) && %i[epoch_time message].all?{ |s| message_object.key?(s) }
|
118
|
+
timestamp = message_object[:epoch_time]
|
119
|
+
message = message_object[:message]
|
120
|
+
end
|
121
|
+
|
122
|
+
{ timestamp: timestamp, message: message }
|
123
|
+
end
|
115
124
|
end
|
116
125
|
end
|
117
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudwatchlogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zane Shannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuid
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: 1.3.6
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
89
|
+
rubygems_version: 3.2.3
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Amazon CloudWatch Logs compatiable logger for ruby.
|