Module: Protobuf::Logger::LogMethods

Overview

LogMethods module for log method including, e.g.:

class MyClass include Protobuf::Logger::LogMethods ... end

Produce a module to allow "include" in other classes to avoid cluttering the namespace of the including class with the other methods defined above

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

When included, also extend the LogMethods module for class access.



62
63
64
# File 'lib/protobuf/logger.rb', line 62

def self.included(base)
  base.extend(LogMethods)
end

Instance Method Details

#log_exception(ex) ⇒ Object

We often want to log an exception, so let's make that a core concern of the logger.



69
70
71
72
73
# File 'lib/protobuf/logger.rb', line 69

def log_exception(ex)
  log_error { ex.message }
  log_error { ex.backtrace[0..5].join("\n") }
  log_debug { ex.backtrace.join("\n") }
end

#log_signatureObject



75
76
77
# File 'lib/protobuf/logger.rb', line 75

def log_signature
  @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]"
end

#sign_message(message) ⇒ Object



79
80
81
# File 'lib/protobuf/logger.rb', line 79

def sign_message(message)
  "#{log_signature} #{message}"
end