Class: PhusionPassenger::AnalyticsLogger::Log
- Defined in:
- lib/phusion_passenger/analytics_logger.rb
Instance Attribute Summary collapse
-
#txn_id ⇒ Object
readonly
Returns the value of attribute txn_id.
Instance Method Summary collapse
- #begin_measure(name, extra_info = nil) ⇒ Object
- #close(flush_to_disk = false) ⇒ Object
- #closed? ⇒ Boolean
- #end_measure(name, error_encountered = false) ⇒ Object
-
#initialize(connection = nil, txn_id = nil) ⇒ Log
constructor
A new instance of Log.
- #measure(name, extra_info = nil) ⇒ Object
- #measured_time_points(name, begin_time, end_time, extra_info = nil) ⇒ Object
- #message(text) ⇒ Object
- #null? ⇒ Boolean
Constructor Details
#initialize(connection = nil, txn_id = nil) ⇒ Log
Returns a new instance of Log.
41 42 43 44 45 46 47 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 41 def initialize(connection = nil, txn_id = nil) if connection @connection = connection @txn_id = txn_id connection.ref end end |
Instance Attribute Details
#txn_id ⇒ Object (readonly)
Returns the value of attribute txn_id.
39 40 41 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 39 def txn_id @txn_id end |
Instance Method Details
#begin_measure(name, extra_info = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 76 def begin_measure(name, extra_info = nil) if extra_info extra_info_base64 = [extra_info].pack("m") extra_info_base64.gsub!("\n", "") extra_info_base64.strip! else extra_info_base64 = nil end times = NativeSupport.process_times "BEGIN: #{name} (#{.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)}) #{extra_info_base64}" end |
#close(flush_to_disk = false) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 124 def close(flush_to_disk = false) @connection.synchronize do return if !@connection.connected? begin # We need an ACK here. See thread_handler.rb finalize_request. @connection.channel.write("closeTransaction", @txn_id, AnalyticsLogger., true) result = @connection.channel.read if result != ["ok"] raise "Expected logging agent to respond with 'ok', but got #{result.inspect} instead" end if flush_to_disk @connection.channel.write("flush") result = @connection.channel.read if result != ["ok"] raise "Invalid logging agent response #{result.inspect} to the 'flush' command" end end rescue SystemCallError, IOError => e @connection.disconnect DebugLogging.warn("Error communicating with the logging agent: #{e.}") rescue Exception => e @connection.disconnect raise e ensure @connection.unref @connection = nil end end if @connection end |
#closed? ⇒ Boolean
155 156 157 158 159 160 161 162 163 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 155 def closed? if @connection @connection.synchronize do return !@connection.connected? end else return nil end end |
#end_measure(name, error_encountered = false) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 88 def end_measure(name, error_encountered = false) times = NativeSupport.process_times if error_encountered "FAIL: #{name} (#{.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})" else "END: #{name} (#{.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})" end end |
#measure(name, extra_info = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 97 def measure(name, extra_info = nil) begin_measure(name, extra_info) begin yield rescue Exception error = true is_closed = closed? raise ensure end_measure(name, error) if !is_closed end end |
#measured_time_points(name, begin_time, end_time, extra_info = nil) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 110 def measured_time_points(name, begin_time, end_time, extra_info = nil) if extra_info extra_info_base64 = [extra_info].pack("m") extra_info_base64.gsub!("\n", "") extra_info_base64.strip! else extra_info_base64 = nil end = begin_time.to_i * 1_000_000 + begin_time.usec = end_time.to_i * 1_000_000 + end_time.usec "BEGIN: #{name} (#{.to_s(36)}) #{extra_info_base64}" "END: #{name} (#{.to_s(36)})" end |
#message(text) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 53 def (text) if !@connection = AnalyticsLogger. DebugLogging.trace(3, "[Union Station log to null] #{@txn_id} #{} #{text}") return end @connection.synchronize do return if !@connection.connected? begin = AnalyticsLogger. DebugLogging.trace(3, "[Union Station log] #{@txn_id} #{} #{text}") @connection.channel.write("log", @txn_id, ) @connection.channel.write_scalar(text) rescue SystemCallError, IOError => e @connection.disconnect DebugLogging.warn("Error communicating with the logging agent: #{e.}") rescue Exception => e @connection.disconnect raise e end end end |
#null? ⇒ Boolean
49 50 51 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 49 def null? return !@connection || !@connection.connected? end |