cloudwatchlogger 0.2.1 → 0.3.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 +5 -5
- data/README.md +7 -1
- data/cloudwatchlogger.gemspec +2 -2
- data/lib/cloudwatchlogger.rb +1 -1
- data/lib/cloudwatchlogger/client.rb +12 -3
- data/lib/cloudwatchlogger/client/aws_sdk/threaded.rb +11 -12
- data/lib/cloudwatchlogger/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c2af49513f0c3aa7ab58d1dd9118018ca1adec7fb1335493e0fad7a0a60b6e2
|
4
|
+
data.tar.gz: 3ef0b93addf793462ceec0052acb7c4e13e9fe5e0c59dc9034bb4f1acd1ea5af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3d46c5fe91f1eeb9c2f751263f86bd71194c6d0d8154b15fbe777baa79491aabc297289d245a50eac89fef2bbe661c0d4328eebb0c08171602d31e9c617c06f
|
7
|
+
data.tar.gz: 5d71a3e18b6ee0557710e96b19b6b40e2fc7458cbef0f1906c01629bcd207b48e11e8d03e9d597a8c67160d63937111d2c82bfe7355135d54c4c9d1c3accffe0
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ log = CloudWatchLogger.new({access_key_id: 'YOUR_ACCESS_KEY_ID', secret_access_k
|
|
20
20
|
log.info("Hello World from Ruby")
|
21
21
|
```
|
22
22
|
|
23
|
-
In case you need to pass different region or group's different Log Stream name:
|
23
|
+
The region will default to the value of the environment variable `AWS_REGION`. In case you need to pass different region or group's different Log Stream name:
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
log = CloudWatchLogger.new({
|
@@ -29,6 +29,12 @@ log = CloudWatchLogger.new({
|
|
29
29
|
}, 'YOUR_CLOUDWATCH_LOG_GROUP', 'YOUR_CLOUDWATCH_LOG_STREAM', region: 'YOUR_CLOUDWATCH_REGION' )
|
30
30
|
```
|
31
31
|
|
32
|
+
Provding an empty hash instead of credentials will cause the AWS SDK to search the default credential provider chain for credentials, namely:
|
33
|
+
|
34
|
+
1. Environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
|
35
|
+
1. Amazon ECS container credentials (task role)
|
36
|
+
1. Instance profile credentials (IAM role)
|
37
|
+
|
32
38
|
### With Rails
|
33
39
|
|
34
40
|
config/environments/production.rb
|
data/cloudwatchlogger.gemspec
CHANGED
@@ -5,10 +5,10 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'cloudwatchlogger'
|
6
6
|
s.version = CloudWatchLogger::VERSION
|
7
7
|
s.date = Time.now
|
8
|
-
s.summary = '
|
8
|
+
s.summary = 'Amazon CloudWatch Logs compatiable logger for ruby.'
|
9
9
|
s.description = 'Logger => CloudWatchLogs'
|
10
10
|
|
11
|
-
s.license = "
|
11
|
+
s.license = "MIT"
|
12
12
|
|
13
13
|
s.authors = ["Zane Shannon"]
|
14
14
|
s.email = 'z@zcs.me'
|
data/lib/cloudwatchlogger.rb
CHANGED
@@ -11,7 +11,7 @@ module CloudWatchLogger
|
|
11
11
|
logger = Logger.new(client)
|
12
12
|
|
13
13
|
if client.respond_to?(:formatter)
|
14
|
-
logger.formatter = client.formatter
|
14
|
+
logger.formatter = client.formatter(opts[:format])
|
15
15
|
elsif client.respond_to?(:datetime_format)
|
16
16
|
logger.datetime_format = client.datetime_format
|
17
17
|
end
|
@@ -33,11 +33,11 @@ module CloudWatchLogger
|
|
33
33
|
end.join(', ')
|
34
34
|
end
|
35
35
|
|
36
|
-
def formatter
|
36
|
+
def formatter(format=nil)
|
37
37
|
proc do |severity, datetime, progname, msg|
|
38
38
|
processid = Process.pid
|
39
|
-
if
|
40
|
-
MultiJson.dump(msg.merge(severity: severity,
|
39
|
+
if format == :json && msg.is_a?(Hash)
|
40
|
+
message = MultiJson.dump(msg.merge(severity: severity,
|
41
41
|
datetime: datetime,
|
42
42
|
progname: progname,
|
43
43
|
pid: processid))
|
@@ -45,6 +45,11 @@ module CloudWatchLogger
|
|
45
45
|
message = "#{datetime} "
|
46
46
|
message << massage_message(msg, severity, processid)
|
47
47
|
end
|
48
|
+
|
49
|
+
{
|
50
|
+
message: message,
|
51
|
+
epoch_time: epoch_from(datetime)
|
52
|
+
}
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
@@ -80,6 +85,10 @@ module CloudWatchLogger
|
|
80
85
|
uuid = UUID.new
|
81
86
|
@log_stream_name ||= "#{Socket.gethostname}-#{uuid.generate}"
|
82
87
|
end
|
88
|
+
|
89
|
+
def epoch_from(datetime)
|
90
|
+
(datetime.utc.to_f.round(3) * 1000).to_i
|
91
|
+
end
|
83
92
|
end
|
84
93
|
end
|
85
94
|
end
|
@@ -50,16 +50,16 @@ module CloudWatchLogger
|
|
50
50
|
loop do
|
51
51
|
connect!(opts) if @client.nil?
|
52
52
|
|
53
|
-
|
54
|
-
break if
|
53
|
+
message_object = @queue.pop
|
54
|
+
break if message_object == :__delivery_thread_exit_signal__
|
55
55
|
|
56
56
|
begin
|
57
57
|
event = {
|
58
58
|
log_group_name: @log_group_name,
|
59
59
|
log_stream_name: @log_stream_name,
|
60
60
|
log_events: [{
|
61
|
-
timestamp:
|
62
|
-
message:
|
61
|
+
timestamp: message_object[:epoch_time],
|
62
|
+
message: message_object[:message]
|
63
63
|
}]
|
64
64
|
}
|
65
65
|
event[:sequence_token] = @sequence_token if @sequence_token
|
@@ -93,13 +93,11 @@ module CloudWatchLogger
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def connect!(opts = {})
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
http_read_timeout: opts[:read_timeout]
|
102
|
-
)
|
96
|
+
args = { http_open_timeout: opts[:open_timeout], http_read_timeout: opts[:read_timeout] }
|
97
|
+
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] } : {} )
|
99
|
+
|
100
|
+
@client = Aws::CloudWatchLogs::Client.new(args)
|
103
101
|
begin
|
104
102
|
@client.create_log_stream(
|
105
103
|
log_group_name: @log_group_name,
|
@@ -110,7 +108,8 @@ module CloudWatchLogger
|
|
110
108
|
log_group_name: @log_group_name
|
111
109
|
)
|
112
110
|
retry
|
113
|
-
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException
|
111
|
+
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException,
|
112
|
+
Aws::CloudWatchLogs::Errors::AccessDeniedException
|
114
113
|
end
|
115
114
|
end
|
116
115
|
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: 0.3.0
|
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: 2020-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuid
|
@@ -69,7 +69,7 @@ files:
|
|
69
69
|
- lib/cloudwatchlogger/version.rb
|
70
70
|
homepage: http://github.com/zshannon/cloudwatchlogger
|
71
71
|
licenses:
|
72
|
-
-
|
72
|
+
- MIT
|
73
73
|
metadata: {}
|
74
74
|
post_install_message:
|
75
75
|
rdoc_options: []
|
@@ -86,9 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: 1.3.6
|
88
88
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.6.11
|
89
|
+
rubygems_version: 3.0.3
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
|
-
summary:
|
92
|
+
summary: Amazon CloudWatch Logs compatiable logger for ruby.
|
94
93
|
test_files: []
|