Class: NRSER::Log::Plugins::Notify
- Inherits:
-
NRSER::Log::Plugin
- Object
- NRSER::Log::Plugin
- NRSER::Log::Plugins::Notify
- Defined in:
- lib/nrser/log/plugins/notify.rb
Instance Attribute Summary collapse
-
#activate ⇒ #to_s
readonly
The ‘:activate` option value.
-
#execute ⇒ #to_s
readonly
The ‘:execute` option value.
-
#open ⇒ #to_s
readonly
The ‘:open` option value.
-
#sender ⇒ #to_s
readonly
The ‘:sender` option value.
-
#sound ⇒ #to_s
readonly
The ‘:sound` option value.
Instance Method Summary collapse
-
#call(level:, message:, payload:, exception:, metric:, &block) ⇒ Boolean
Handle a log call.
- #group ⇒ Object
- #icon(level) ⇒ Object
-
#initialize(logger, title: nil, subtitle: nil, group: nil, activate: nil, open: nil, execute: nil, sender: nil, sound: nil, icon: nil) ⇒ Notify
constructor
Construction ========================================================================.
-
#options(level:, message:, payload:, exception:) ⇒ Hash<Symbol, String>
Get the options for Notify.notify for a log call.
- #subtitle ⇒ Object
-
#title(level) ⇒ Object
Instance Methods ========================================================================.
Constructor Details
#initialize(logger, title: nil, subtitle: nil, group: nil, activate: nil, open: nil, execute: nil, sender: nil, sound: nil, icon: nil) ⇒ Notify
Construction
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/nrser/log/plugins/notify.rb', line 68 def initialize logger, title: nil, subtitle: nil, group: nil, activate: nil, open: nil, execute: nil, sender: nil, sound: nil, icon: nil super logger @title = title @subtitle = subtitle @group = group @activate = activate @open = open @execute = execute @sender = sender @sound = sound @icon = icon end |
Instance Attribute Details
#activate ⇒ #to_s (readonly)
Returns The ‘:activate` option value.
42 43 44 |
# File 'lib/nrser/log/plugins/notify.rb', line 42 def activate @activate end |
#execute ⇒ #to_s (readonly)
Returns The ‘:execute` option value.
52 53 54 |
# File 'lib/nrser/log/plugins/notify.rb', line 52 def execute @execute end |
#open ⇒ #to_s (readonly)
Returns The ‘:open` option value.
47 48 49 |
# File 'lib/nrser/log/plugins/notify.rb', line 47 def open @open end |
#sender ⇒ #to_s (readonly)
Returns The ‘:sender` option value.
57 58 59 |
# File 'lib/nrser/log/plugins/notify.rb', line 57 def sender @sender end |
#sound ⇒ #to_s (readonly)
Returns The ‘:sound` option value.
62 63 64 |
# File 'lib/nrser/log/plugins/notify.rb', line 62 def sound @sound end |
Instance Method Details
#call(level:, message:, payload:, exception:, metric:, &block) ⇒ Boolean
Handle a log call. Calls ‘super`, and if that indicates that the log was sent then dispatches the notification¹.
> ¹ Except for ‘trace` level log messages - we never notify of those.
def call level, message = nil, payload = nil, exception = nil, &block
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/nrser/log/plugins/notify.rb', line 155 def call level:, message:, payload:, exception:, metric:, &block super.tap { |was_logged| # TODO Doesn't seem the return value *totally* represents if the log was # sent or not... there's some additional logic? # # Also, we never notify for `trace` log messages regardless of log level. # if level != :trace && was_logged NRSER::Notify.notify \ , **( level: level, message: , payload: payload, exception: exception, ) end } end |
#group ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/nrser/log/plugins/notify.rb', line 109 def group return @group unless @group.nil? if SemanticLogger.application != 'Semantic Logger' return SemanticLogger.application end $0 # or Process.pid ? end |
#icon(level) ⇒ Object
104 105 106 |
# File 'lib/nrser/log/plugins/notify.rb', line 104 def icon level @icon || NRSER::Notify::ROOT / 'assets' / 'notify' / "#{ level }.png" end |
#options(level:, message:, payload:, exception:) ⇒ Hash<Symbol, String>
Right now, Notify.notify only supports [terminal-notifier][] as a backend, and passes the options directly, so these are really the options for TerminalNotifier.notify.
Get the options for Notify.notify for a log call.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/nrser/log/plugins/notify.rb', line 129 def level:, message:, payload:, exception: { title: title( level ), subtitle: subtitle, group: group, activate: activate, open: open, execute: execute, sender: sender, sound: sound, appIcon: icon( level ), }.compact.transform_values &:to_s end |
#subtitle ⇒ Object
99 100 101 |
# File 'lib/nrser/log/plugins/notify.rb', line 99 def subtitle @subtitle end |
#title(level) ⇒ Object
Instance Methods
94 95 96 |
# File 'lib/nrser/log/plugins/notify.rb', line 94 def title level @title || "#{ level.to_s.upcase } - #{ logger.name }" end |