Class: Rapid::Model::Log

Inherits:
Compo::Branches::Leaf
  • Object
show all
Includes:
ModelObject
Defined in:
lib/ury_rapid/model/log.rb

Overview

An object that represents Rapid's error/debugging log

This is part of the model to allow easy access to the logger in areas such as the server and service, without needing to pass it in explicitly. It also allows the log to be treated like any other bit of data Rapid holds.

In future, the log may be readable using the Rapid API.

Instance Attribute Summary

Attributes included from ModelObject

#handler_target

Instance Method Summary collapse

Methods included from ModelObject

#default_handler_target, #default_id, #flat, #get, #kill, #post_to_parent, #register_handler, #replace

Methods included from Updatable

#deregister_from_updates, #notify_delete, #notify_update, #register_for_updates, #register_update_channel

Constructor Details

#initialize(logger) ⇒ Log

Initialises the Log

Examples:

Initialising a log with an instance of a Ruby Logger

log = Log.new(Logger.new(STDOUT))

25
26
27
28
# File 'lib/ury_rapid/model/log.rb', line 25

def initialize(logger)
  super()
  @logger = logger
end

Instance Method Details

#insert(id, payload) ⇒ Object

POSTs an entry to this Log

The ID should be one of :info, :debug, :warn, :fatal or :error, and the payload should be the string to log.

Examples:

Posting an error message to the log.

log.insert(:error, 'Somebody famous has died.')

45
46
47
48
# File 'lib/ury_rapid/model/log.rb', line 45

def insert(id, payload)
  fail(ArgumentError) unless %i(debug info warn fatal error).include?(id)
  @logger.send(id, payload)
end