lib/oboe/api/logging.rb in oboe-2.7.1.7-java vs lib/oboe/api/logging.rb in oboe-2.7.2.fuchs1

- old
+ new

@@ -1,12 +1,13 @@ # Copyright (c) 2013 AppNeta, Inc. # All rights reserved. module Oboe module API + ## + # This modules provides the X-Trace logging facilities. module Logging - # Public: Report an event in an active trace. # # layer - The layer the reported event belongs to # label - The label for the reported event. See API documentation for # reserved labels and usage. @@ -18,11 +19,11 @@ # log('logical_layer', 'entry') # log('logical_layer', 'info', { :list_length => 20 }) # log('logical_layer', 'exit') # # Returns nothing. - def log(layer, label, opts={}) + def log(layer, label, opts = {}) log_event(layer, label, Oboe::Context.createEvent, opts) end # Public: Report an exception. # @@ -38,18 +39,18 @@ # raise # end # # Returns nothing. def log_exception(layer, exn) - unless exn.instance_variable_get(:@oboe_logged) - log(layer, 'error', { - :ErrorClass => exn.class.name, - :Message => exn.message, - :Backtrace => exn.backtrace.join("\r\n") - }) - exn.instance_variable_set(:@oboe_logged, true) - end + return if exn.instance_variable_get(:@oboe_logged) + + kvs = { :ErrorClass => exn.class.name, + :Message => exn.message, + :Backtrace => exn.backtrace.join("\r\n") } + + exn.instance_variable_set(:@oboe_logged, true) + log(layer, 'error', kvs) end # Public: Decide whether or not to start a trace, and report an event # appropriately. # @@ -57,46 +58,69 @@ # xtrace - An xtrace metadata string, or nil. # opts - A hash containing key/value pairs that will be reported along # with this event (optional). # # Returns nothing. - def log_start(layer, xtrace, opts={}) - return if Oboe.never? or (opts.has_key?(:URL) and ::Oboe::Util.static_asset?(opts[:URL])) + def log_start(layer, xtrace, opts = {}) + return if Oboe.never? || (opts.key?(:URL) && ::Oboe::Util.static_asset?(opts[:URL])) - if xtrace and not xtrace.to_s.empty? - Oboe::Context.fromString(xtrace) - end + Oboe::Context.fromString(xtrace) if xtrace && !xtrace.to_s.empty? if Oboe.tracing? log_entry(layer, opts) - elsif opts.has_key?('Force') or Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace)) + elsif opts.key?('Force') || Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace)) log_event(layer, 'entry', Oboe::Context.startTrace, opts) end end # Public: Report an exit event. # # layer - The layer the reported event belongs to # # Returns an xtrace metadata string - def log_end(layer, opts={}) + def log_end(layer, opts = {}) log_event(layer, 'exit', Oboe::Context.createEvent, opts) xtrace = Oboe::Context.toString Oboe::Context.clear xtrace end - def log_entry(layer, opts={}, protect_op=nil) - Oboe.layer_op = protect_op if protect_op - log_event(layer, 'entry', Oboe::Context.createEvent, opts) + ## + # Public: Log an entry event + # + # A helper method to create and log an + # entry event + # + # Returns an xtrace metadata string + def log_entry(layer, kvs = {}, op = nil) + Oboe.layer_op = op if op + log_event(layer, 'entry', Oboe::Context.createEvent, kvs) end - def log_exit(layer, opts={}, protect_op=nil) - Oboe.layer_op = nil if protect_op - log_event(layer, 'exit', Oboe::Context.createEvent, opts) + ## + # Public: Log an info event + # + # A helper method to create and log an + # info event + # + # Returns an xtrace metadata string + def log_info(layer, kvs = {}) + log_event(layer, 'info', Oboe::Context.createEvent, kvs) end + ## + # Public: Log an exit event + # + # A helper method to create and log an + # exit event + # + # Returns an xtrace metadata string + def log_exit(layer, kvs = {}, op = nil) + Oboe.layer_op = nil if op + log_event(layer, 'exit', Oboe::Context.createEvent, kvs) + end + # Internal: Report an event. # # layer - The layer the reported event belongs to # label - The label for the reported event. See API documentation for # reserved labels and usage. @@ -110,18 +134,16 @@ # exit = Oboe::Context.createEvent # exit.addEdge(entry.getMetadata) # log_event('rails', 'exit', exit) # # Returns nothing. - def log_event(layer, label, event, opts={}) - if layer - event.addInfo('Layer', layer.to_s) - end + def log_event(layer, label, event, opts = {}) + event.addInfo('Layer', layer.to_s) if layer event.addInfo('Label', label.to_s) opts.each do |k, v| event.addInfo(k.to_s, v.to_s) if valid_key? k - end if !opts.nil? and opts.any? + end if !opts.nil? && opts.any? Oboe::Reporter.sendReport(event) if Oboe.loaded end end end