Class: Wavefront::Logger
- Inherits:
-
Object
- Object
- Wavefront::Logger
- Defined in:
- lib/wavefront-sdk/core/logger.rb
Overview
Log to a user-supplied Ruby logger, or to standard output.
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #format_message(level, msg) ⇒ Object
-
#initialize(opts = {}) ⇒ Logger
constructor
A new instance of Logger.
-
#log(msg, level = :info) ⇒ Object
Send a message to a Ruby logger object if the user supplied one, or print to standard out if not.
- #print_debug_message(msg) ⇒ Object
- #print_error_message(msg) ⇒ Object
- #print_info_message(msg) ⇒ Object
- #print_message(level, msg) ⇒ Object
- #print_warn_message(msg) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 14 |
# File 'lib/wavefront-sdk/core/logger.rb', line 10 def initialize(opts = {}) @logger = opts[:logger] || nil @verbose = opts[:verbose] || nil @debug = opts[:debug] || nil end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
6 7 8 |
# File 'lib/wavefront-sdk/core/logger.rb', line 6 def debug @debug end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/wavefront-sdk/core/logger.rb', line 6 def logger @logger end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/wavefront-sdk/core/logger.rb', line 6 def verbose @verbose end |
Instance Method Details
#format_message(level, msg) ⇒ Object
44 45 46 |
# File 'lib/wavefront-sdk/core/logger.rb', line 44 def (level, msg) format('SDK %s: %s', level.to_s.upcase, msg) end |
#log(msg, level = :info) ⇒ Object
Send a message to a Ruby logger object if the user supplied one, or print to standard out if not.
24 25 26 27 28 29 30 |
# File 'lib/wavefront-sdk/core/logger.rb', line 24 def log(msg, level = :info) if logger logger.send(level, msg) else (level, msg) end end |
#print_debug_message(msg) ⇒ Object
48 49 50 |
# File 'lib/wavefront-sdk/core/logger.rb', line 48 def (msg) puts msg if debug end |
#print_error_message(msg) ⇒ Object
60 61 62 |
# File 'lib/wavefront-sdk/core/logger.rb', line 60 def (msg) warn msg end |
#print_info_message(msg) ⇒ Object
52 53 54 |
# File 'lib/wavefront-sdk/core/logger.rb', line 52 def (msg) puts msg if debug || verbose end |
#print_message(level, msg) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wavefront-sdk/core/logger.rb', line 32 def (level, msg) method = format('print_%s_message', level).to_sym msg = (level, msg) if respond_to?(:method) send(method, msg) else (format('undefined message level:%s', level)) (msg) end end |
#print_warn_message(msg) ⇒ Object
56 57 58 |
# File 'lib/wavefront-sdk/core/logger.rb', line 56 def (msg) warn msg end |