class NRSER::Log::Plugins::Notify

Attributes

activate[R]

@return [#to_s]

The `:activate` option value.
execute[R]

@return [#to_s]

The `:execute` option value.
open[R]

@return [#to_s]

The `:open` option value.
sender[R]

@return [#to_s]

The `:sender` option value.
sound[R]

@return [#to_s]

The `:sound` option value.

Public Class Methods

new(logger, title: nil, subtitle: nil, group: nil, activate: nil, open: nil, execute: nil, sender: nil, sound: nil, icon: nil) click to toggle source

Construction

Calls superclass method
# 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

Public Instance Methods

call(level:, message:, payload:, exception:, metric:, &block) click to toggle source

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.

@param (see NRSER::Log::Plugin#call)

@return [Boolean]

`true` if the log was sent (met level and not filtered).

def call level, message = nil, payload = nil, exception = nil, &block

Calls superclass method
# 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 \
        message,
        **options(
          level: level,
          message: message,
          payload: payload,
          exception: exception,
        )
    end
  }
end
group() click to toggle source
# 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) click to toggle source
# 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: { title: title( level ), subtitle: subtitle, group: group, activate: activate, open: open, execute: execute, sender: sender, sound: sound, appIcon: icon( level ), }) click to toggle source

Get the options for {NRSER::Notify.notify} for a log call.

@note

Right now, {NRSER::Notify.notify} only supports [terminal-notifier][]
as a backend, and passes the options directly, so these are really the
options for {TerminalNotifier.notify}.

@return [Hash<Symbol, String>]

# File lib/nrser/log/plugins/notify.rb, line 129
def options 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() click to toggle source
# File lib/nrser/log/plugins/notify.rb, line 99
def subtitle
  @subtitle
end
title(level) click to toggle source

Instance Methods

# File lib/nrser/log/plugins/notify.rb, line 94
def title level
  @title || "#{ level.to_s.upcase } - #{ logger.name }"
end