Class: HasHelpers::LogNotifier
- Inherits:
-
Object
- Object
- HasHelpers::LogNotifier
- Defined in:
- lib/has_helpers/utils/log_notifier.rb
Constant Summary collapse
- MAX_SNS_SUBJECT_LENGTH =
99
Class Method Summary collapse
-
.notify(exception_or_msg, subject: nil, user: nil) ⇒ Object
This uses a default notifier to write the exception_or_msg to the console.
Instance Method Summary collapse
-
#initialize(notify_console: true) ⇒ LogNotifier
constructor
Instantiates an HasHelpers::HQNotifier that outputs to ELK, and/or the console depending on these options: - notify_console: By default, this notifier will output to the console.
-
#notify(exception_or_msg, subject: nil, user: nil, backtrace: caller) ⇒ Object
The argument can be an Exception or a String.
Constructor Details
#initialize(notify_console: true) ⇒ LogNotifier
Instantiates an HasHelpers::HQNotifier that outputs to ELK, and/or the console depending on these options:
- notify_console: By default, this notifier will output to the console. Set this to false if you don't want log messages copied to the console.
34 35 36 |
# File 'lib/has_helpers/utils/log_notifier.rb', line 34 def initialize(notify_console: true) @notify_console = notify_console end |
Class Method Details
.notify(exception_or_msg, subject: nil, user: nil) ⇒ Object
This uses a default notifier to write the exception_or_msg to the console
22 23 24 25 |
# File 'lib/has_helpers/utils/log_notifier.rb', line 22 def self.notify(exception_or_msg, subject: nil, user: nil) @default_notifier ||= HasHelpers::LogNotifier.new @default_notifier.notify(exception_or_msg, subject: subject, user: user) end |
Instance Method Details
#notify(exception_or_msg, subject: nil, user: nil, backtrace: caller) ⇒ Object
The argument can be an Exception or a String. Paramerters are:
- subject: an optional subject for SNS messages
- file_path: required if the argument is String | Optional if Exception
- line_number: required if the argument is String | Optional if Exception
- function_name: required if the argument is String | Optional if Exception
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/has_helpers/utils/log_notifier.rb', line 44 def notify(exception_or_msg, subject: nil, user: nil, backtrace: caller) # rubocop:disable Lint/UnusedMethodArgument unless exception_or_msg.is_a?(Exception) || exception_or_msg.is_a?(String) raise "HasHelpers::HQNotifier expected an Exception or String, but got a #{exception_or_msg.class}." end = (exception_or_msg) exception = exception_or_msg.is_a?(Exception) ? exception_or_msg : (exception_or_msg, backtrace: backtrace) # rubocop:disable Lint/UselessAssignment puts if @notify_console end |