cloudwatchlogger 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6ca7c28dbaa9d4cd65eb71b0fbfae51d8e1933a
4
- data.tar.gz: 434c182d0862b63b6ab7d0c8ac6a020def97ceb5
3
+ metadata.gz: fb1e357bd158f76606d1e13a03ed520f6dead066
4
+ data.tar.gz: 4dd0d17ac08f99ff207519b1b9e5ad7c0120cc8d
5
5
  SHA512:
6
- metadata.gz: cc7ed35ff37a17bd5a73effbd298ec14f7585a37a215254591efb7b982b3bf6bcd0b5fcab2760c0a315c58147f1e29667973e6b21ff5cf72f9c6826dfe90f9df
7
- data.tar.gz: b4fdd61589e900f84a528c7ae58de745e9642e48891cb5c73545fd8638507c9fd313dd551c9018d4d8839782727163b72c02a3573210631bd424c4f5a0abd106
6
+ metadata.gz: 9ae37a40c94f7f2b7b82702ff319d3511dc0baf64e70e095b2bfd2cfaf37bb06955dd083426cb068412f1dcdfc560b65ef586c4d50243ea902792162eb11ec59
7
+ data.tar.gz: e0c060b9ec7d9001a450b0da9d611e7d1bd1c77cf70278e32f38c646c64effe4dd7bdb997dfec03dfbc1603d878f20b642b243fefe177d9e37e5a85081f1dc67
data/README.md CHANGED
@@ -80,6 +80,11 @@ Will produce the following log message in CloudWatch Logs:
80
80
  "<Date> severity=WARN, boom=box, bar=soap"
81
81
  ```
82
82
 
83
+ Releasing
84
+ -----
85
+
86
+ `rake release`
87
+
83
88
  Bugs
84
89
  -----
85
90
 
@@ -3,11 +3,10 @@ require File.join(File.dirname(__FILE__), 'cloudwatchlogger', 'client')
3
3
  require 'logger'
4
4
 
5
5
  module CloudWatchLogger
6
-
7
6
  class LogGroupNameRequired < ArgumentError; end
8
7
  class LogEventRejected < ArgumentError; end
9
8
 
10
- def self.new(credentials, log_group_name, log_stream_name=nil, opts={})
9
+ def self.new(credentials, log_group_name, log_stream_name = nil, opts = {})
11
10
  client = CloudWatchLogger::Client.new(credentials, log_group_name, log_stream_name, opts)
12
11
  logger = Logger.new(client)
13
12
 
@@ -19,5 +18,4 @@ module CloudWatchLogger
19
18
 
20
19
  logger
21
20
  end
22
-
23
- end
21
+ end
@@ -5,44 +5,42 @@ require 'uuid'
5
5
 
6
6
  module CloudWatchLogger
7
7
  module Client
8
-
9
- def self.new(credentials, log_group_name, log_stream_name=nil, opts={})
8
+ def self.new(credentials, log_group_name, log_stream_name = nil, opts = {})
10
9
  unless log_group_name
11
- raise LogGroupNameRequired.new
10
+ raise LogGroupNameRequired, 'log_group_name is required'
12
11
  end
13
12
 
14
13
  CloudWatchLogger::Client::AWS_SDK.new(credentials, log_group_name, log_stream_name, opts)
15
14
  end
16
15
 
17
16
  module InstanceMethods
18
-
19
- def masherize_key(prefix,key)
20
- [prefix,key.to_s].compact.join('.')
17
+ def masherize_key(prefix, key)
18
+ [prefix, key.to_s].compact.join('.')
21
19
  end
22
20
 
23
- def masher(hash, prefix=nil)
21
+ def masher(hash, prefix = nil)
24
22
  hash.map do |v|
25
23
  if v[1].is_a?(Hash)
26
- masher(v[1],masherize_key(prefix,v[0]))
24
+ masher(v[1], masherize_key(prefix, v[0]))
27
25
  else
28
- "#{masherize_key(prefix,v[0])}=" << case v[1]
29
- when Symbol
30
- v[1].to_s
31
- else
32
- v[1].inspect
33
- end
26
+ "#{masherize_key(prefix, v[0])}=" << case v[1]
27
+ when Symbol
28
+ v[1].to_s
29
+ else
30
+ v[1].inspect
31
+ end
34
32
  end
35
- end.join(", ")
33
+ end.join(', ')
36
34
  end
37
35
 
38
36
  def formatter
39
37
  proc do |severity, datetime, progname, msg|
40
- processid=Process.pid
38
+ processid = Process.pid
41
39
  if @format == :json && msg.is_a?(Hash)
42
- MultiJson.dump(msg.merge({ :severity => severity,
43
- :datetime => datetime,
44
- :progname => progname,
45
- :pid => processid }))
40
+ MultiJson.dump(msg.merge(severity: severity,
41
+ datetime: datetime,
42
+ progname: progname,
43
+ pid: processid))
46
44
  else
47
45
  message = "#{datetime} "
48
46
  message << massage_message(msg, severity, processid)
@@ -51,18 +49,18 @@ module CloudWatchLogger
51
49
  end
52
50
 
53
51
  def massage_message(incoming_message, severity, processid)
54
- outgoing_message = ""
55
-
52
+ outgoing_message = ''
53
+
56
54
  outgoing_message << "pid=#{processid}, thread=#{Thread.current.object_id}, severity=#{severity}, "
57
-
58
- case incoming_message
59
- when Hash
60
- outgoing_message << masher(incoming_message)
61
- when String
62
- outgoing_message << incoming_message
63
- else
64
- outgoing_message << incoming_message.inspect
65
- end
55
+
56
+ outgoing_message << case incoming_message
57
+ when Hash
58
+ masher(incoming_message)
59
+ when String
60
+ incoming_message
61
+ else
62
+ incoming_message.inspect
63
+ end
66
64
  outgoing_message
67
65
  end
68
66
 
@@ -73,18 +71,17 @@ module CloudWatchLogger
73
71
  def setup_log_group_name(name)
74
72
  @log_group_name = name
75
73
  end
76
-
74
+
77
75
  def setup_log_stream_name(name)
78
- @log_stream_name = name
79
- if @log_stream_name.nil?
80
- uuid = UUID.new
81
- @log_stream_name = "#{Socket.gethostname}-#{uuid.generate}"
82
- end
76
+ @log_stream_name = name || default_log_stream_name
83
77
  end
84
78
 
79
+ def default_log_stream_name
80
+ uuid = UUID.new
81
+ @log_stream_name ||= "#{Socket.gethostname}-#{uuid.generate}"
82
+ end
85
83
  end
86
-
87
84
  end
88
85
  end
89
86
 
90
- require File.join(File.dirname(__FILE__), 'client', 'aws_sdk')
87
+ require File.join(File.dirname(__FILE__), 'client', 'aws_sdk')
@@ -7,7 +7,7 @@ module CloudWatchLogger
7
7
 
8
8
  attr_reader :input_uri, :deliverer
9
9
 
10
- def initialize(credentials, log_group_name, log_stream_name, opts={})
10
+ def initialize(credentials, log_group_name, log_stream_name, opts = {})
11
11
  setup_credentials(credentials)
12
12
  setup_log_group_name(log_group_name)
13
13
  setup_log_stream_name(log_stream_name)
@@ -23,4 +23,4 @@ module CloudWatchLogger
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -4,13 +4,15 @@ require 'thread'
4
4
  module CloudWatchLogger
5
5
  module Client
6
6
  class AWS_SDK
7
-
8
7
  # Used by the Threaded client to manage the delivery thread
9
8
  # recreating it if is lost due to a fork.
10
9
  #
11
10
  class DeliveryThreadManager
12
- def initialize(credentials, log_group_name, log_stream_name, opts={})
13
- @credentials, @log_group_name, @log_stream_name, @opts = credentials, log_group_name, log_stream_name, opts
11
+ def initialize(credentials, log_group_name, log_stream_name, opts = {})
12
+ @credentials = credentials
13
+ @log_group_name = log_group_name
14
+ @log_stream_name = log_stream_name
15
+ @opts = opts
14
16
  start_thread
15
17
  end
16
18
 
@@ -18,9 +20,9 @@ module CloudWatchLogger
18
20
  def deliver(message)
19
21
  start_thread unless @thread.alive?
20
22
  @thread.deliver(message)
21
- #Race condition? Sometimes we need to rescue this and start a new thread
23
+ # Race condition? Sometimes we need to rescue this and start a new thread
22
24
  rescue NoMethodError
23
- @thread.kill #Try not to leak threads, should already be dead anyway
25
+ @thread.kill # Try not to leak threads, should already be dead anyway
24
26
  start_thread
25
27
  retry
26
28
  end
@@ -33,21 +35,20 @@ module CloudWatchLogger
33
35
  end
34
36
 
35
37
  class DeliveryThread < Thread
36
-
37
- def initialize(credentials, log_group_name, log_stream_name, opts={})
38
- @credentials, @log_group_name, @log_stream_name, @opts = credentials, log_group_name, log_stream_name, opts
38
+ def initialize(credentials, log_group_name, log_stream_name, opts = {})
39
39
  opts[:open_timeout] = opts[:open_timeout] || 120
40
40
  opts[:read_timeout] = opts[:read_timeout] || 120
41
+ @credentials = credentials
42
+ @log_group_name = log_group_name
43
+ @log_stream_name = log_stream_name
44
+ @opts = opts
41
45
 
42
46
  @queue = Queue.new
43
47
  @exiting = false
44
48
 
45
49
  super do
46
50
  loop do
47
-
48
- if @client.nil?
49
- connect! opts
50
- end
51
+ connect!(opts) if @client.nil?
51
52
 
52
53
  msg = @queue.pop
53
54
  break if msg == :__delivery_thread_exit_signal__
@@ -57,14 +58,11 @@ module CloudWatchLogger
57
58
  log_group_name: @log_group_name,
58
59
  log_stream_name: @log_stream_name,
59
60
  log_events: [{
60
- timestamp: (Time.now.utc.to_f.round(3)*1000).to_i,
61
+ timestamp: (Time.now.utc.to_f.round(3) * 1000).to_i,
61
62
  message: msg
62
63
  }]
63
64
  }
64
-
65
- if token = @sequence_token
66
- event[:sequence_token] = token
67
- end
65
+ event[:sequence_token] = @sequence_token if @sequence_token
68
66
  response = @client.put_log_events(event)
69
67
  unless response.rejected_log_events_info.nil?
70
68
  raise CloudWatchLogger::LogEventRejected
@@ -77,10 +75,10 @@ module CloudWatchLogger
77
75
  end
78
76
  end
79
77
 
80
- at_exit {
78
+ at_exit do
81
79
  exit!
82
80
  join
83
- }
81
+ end
84
82
  end
85
83
 
86
84
  # Signals the queue that we're exiting
@@ -94,7 +92,7 @@ module CloudWatchLogger
94
92
  @queue.push(message)
95
93
  end
96
94
 
97
- def connect!(opts={})
95
+ def connect!(opts = {})
98
96
  @client = Aws::CloudWatchLogs::Client.new(
99
97
  region: @opts[:region] || 'us-east-1',
100
98
  access_key_id: @credentials[:access_key_id],
@@ -107,16 +105,15 @@ module CloudWatchLogger
107
105
  log_group_name: @log_group_name,
108
106
  log_stream_name: @log_stream_name
109
107
  )
110
- rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => err
108
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException
111
109
  @client.create_log_group(
112
110
  log_group_name: @log_group_name
113
111
  )
114
112
  retry
115
- rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => err
113
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException
116
114
  end
117
115
  end
118
116
  end
119
-
120
117
  end
121
118
  end
122
119
  end
@@ -1,5 +1,3 @@
1
1
  module CloudWatchLogger
2
-
3
- VERSION = '0.2.0'
4
-
2
+ VERSION = '0.2.1'.freeze
5
3
  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.2.0
4
+ version: 0.2.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: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuid