Module: CloudWatchLogger::Client::InstanceMethods
- Included in:
- AWS_SDK
- Defined in:
- lib/cloudwatchlogger/client.rb
Instance Method Summary collapse
- #default_log_stream_name ⇒ Object
- #epoch_from(datetime) ⇒ Object
- #formatter(format = nil) ⇒ Object
- #masher(hash, prefix = nil) ⇒ Object
- #masherize_key(prefix, key) ⇒ Object
- #massage_message(incoming_message, severity, processid) ⇒ Object
- #setup_credentials(credentials) ⇒ Object
- #setup_log_group_name(name) ⇒ Object
- #setup_log_stream_name(name) ⇒ Object
Instance Method Details
#default_log_stream_name ⇒ Object
84 85 86 |
# File 'lib/cloudwatchlogger/client.rb', line 84 def default_log_stream_name @log_stream_name ||= "#{Socket.gethostname}-#{SecureRandom.uuid}" end |
#epoch_from(datetime) ⇒ Object
88 89 90 |
# File 'lib/cloudwatchlogger/client.rb', line 88 def epoch_from(datetime) (datetime.utc.to_f.round(3) * 1000).to_i end |
#formatter(format = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cloudwatchlogger/client.rb', line 36 def formatter(format=nil) proc do |severity, datetime, progname, msg| processid = Process.pid if format == :json && msg.is_a?(Hash) = MultiJson.dump(msg.merge(severity: severity, datetime: datetime, progname: progname, pid: processid)) else = "#{datetime} " << (msg, severity, processid) end { message: , epoch_time: epoch_from(datetime) } end end |
#masher(hash, prefix = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cloudwatchlogger/client.rb', line 21 def masher(hash, prefix = nil) hash.map do |v| if v[1].is_a?(Hash) masher(v[1], masherize_key(prefix, v[0])) else "#{masherize_key(prefix, v[0])}=" << case v[1] when Symbol v[1].to_s else v[1].inspect end end end.join(', ') end |
#masherize_key(prefix, key) ⇒ Object
17 18 19 |
# File 'lib/cloudwatchlogger/client.rb', line 17 def masherize_key(prefix, key) [prefix, key.to_s].compact.join('.') end |
#massage_message(incoming_message, severity, processid) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cloudwatchlogger/client.rb', line 56 def (, severity, processid) = '' << "pid=#{processid}, thread=#{Thread.current.object_id}, severity=#{severity}, " << case when Hash masher() when String else .inspect end end |
#setup_credentials(credentials) ⇒ Object
72 73 74 |
# File 'lib/cloudwatchlogger/client.rb', line 72 def setup_credentials(credentials) @credentials = credentials end |
#setup_log_group_name(name) ⇒ Object
76 77 78 |
# File 'lib/cloudwatchlogger/client.rb', line 76 def setup_log_group_name(name) @log_group_name = name end |
#setup_log_stream_name(name) ⇒ Object
80 81 82 |
# File 'lib/cloudwatchlogger/client.rb', line 80 def setup_log_stream_name(name) @log_stream_name = name || default_log_stream_name end |