Module: App47Logger
Overview
Mixin for App47 objects to handle logging in both the rails environment as well as the delayed jobs environment that doesn’t know about Rails.logger
Provides ways to log at the class level as well as instance level.
Usage:
App47Logger.log_debug('meesage')
or
class ClassName
include App47Logger
def method_name
log_debug('message')
end
Class Method Summary collapse
-
.log_debug(message) ⇒ Object
Log a debug messages.
-
.log_error(message, exception = nil) ⇒ Object
Log an error messages.
-
.log_exception(level, exception = nil, max_frame = 9) ⇒ Object
Log a given exception, but only the first 10 lines in anything but test.
-
.log_message(level, message) ⇒ Object
Log a given message at the given level.
-
.log_warn(message, exception = nil) ⇒ Object
Log a warning messages.
Instance Method Summary collapse
-
#log_debug(message) ⇒ Object
Log a debug message as part of the mixin.
-
#log_error(message, exception = nil) ⇒ Object
Log an error message as part of the mixin.
-
#log_message(level, message) ⇒ Object
Log a debug message as part of the mixin.
-
#log_warn(message, exception = nil) ⇒ Object
Log a warning message as part of the mixin.
Class Method Details
.log_debug(message) ⇒ Object
Log a debug messages
26 27 28 |
# File 'lib/models/concerns/app47_logger.rb', line 26 def self.log_debug() :debug, end |
.log_error(message, exception = nil) ⇒ Object
Log an error messages
-
Prints the messages
-
If an exception is passed n
2a prints the exception message
2b prints the stack trace
51 52 53 54 |
# File 'lib/models/concerns/app47_logger.rb', line 51 def self.log_error(, exception = nil) :error, log_exception :error, exception end |
.log_exception(level, exception = nil, max_frame = 9) ⇒ Object
Log a given exception, but only the first 10 lines in anything but test.
In testing, we want the full stack to know the test case that failed.
61 62 63 64 65 66 67 |
# File 'lib/models/concerns/app47_logger.rb', line 61 def self.log_exception(level, exception = nil, max_frame = 9) return if exception.blank? max_frame = -1 if ENV['RACK_ENV'].eql?('test') (level, exception.) exception.backtrace[0..max_frame].each { |frame| (level, frame) } unless exception.backtrace.blank? end |
.log_message(level, message) ⇒ Object
Log a given message at the given level
72 73 74 75 76 77 78 79 80 |
# File 'lib/models/concerns/app47_logger.rb', line 72 def self.(level, ) if ENV['AWS_LAMBDA_FUNCTION_VERSION'].nil? puts "#{level}: #{}" else Logger.new($stdout).send(level, ) end rescue StandardError puts "#{level}: #{}" end |
.log_warn(message, exception = nil) ⇒ Object
Log a warning messages
-
Prints the messages
-
If an exception is passed n
2a prints the exception message
2b prints the stack trace
38 39 40 41 |
# File 'lib/models/concerns/app47_logger.rb', line 38 def self.log_warn(, exception = nil) :warn, log_exception :warn, exception end |
Instance Method Details
#log_debug(message) ⇒ Object
Log a debug message as part of the mixin
92 93 94 |
# File 'lib/models/concerns/app47_logger.rb', line 92 def log_debug() App47Logger.log_debug end |
#log_error(message, exception = nil) ⇒ Object
Log an error message as part of the mixin
106 107 108 |
# File 'lib/models/concerns/app47_logger.rb', line 106 def log_error(, exception = nil) App47Logger.log_error , exception end |
#log_message(level, message) ⇒ Object
Log a debug message as part of the mixin
85 86 87 |
# File 'lib/models/concerns/app47_logger.rb', line 85 def (level, ) App47Logger. level, end |
#log_warn(message, exception = nil) ⇒ Object
Log a warning message as part of the mixin
99 100 101 |
# File 'lib/models/concerns/app47_logger.rb', line 99 def log_warn(, exception = nil) App47Logger.log_warn , exception end |