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.



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

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.



76
77
78
79
80
# File 'lib/protobuf/logger.rb', line 76

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



82
83
84
# File 'lib/protobuf/logger.rb', line 82

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

#sign_message(message) ⇒ Object



86
87
88
# File 'lib/protobuf/logger.rb', line 86

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