Class: Urbivore::MessagePacket
- Inherits:
-
Object
- Object
- Urbivore::MessagePacket
- Includes:
- Interface
- Defined in:
- lib/urbivore/message_packet.rb
Constant Summary
Constants included from Interface
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
instance methods.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MessagePacket
constructor
A new instance of MessagePacket.
- #message_collector(message_object) ⇒ Object
- #messages(requested = nil) ⇒ Object
-
#submit ⇒ Object
send self to the logging machine.
-
#submit! ⇒ Object
as above, but raise exception when trying to submit an already submitted log.
Methods included from Interface
#add, #append_message, #available_levels, #current_levels, #default_level, #default_levels, #default_logger, #generate_message_object, #levels_by_minimum, #levels_by_subset
Constructor Details
#initialize(options = {}) ⇒ MessagePacket
Returns a new instance of MessagePacket.
19 20 21 22 23 24 25 26 |
# File 'lib/urbivore/message_packet.rb', line 19 def initialize( = {}) @logger = [:default_level] || self.class.logger || default_logger @default_level = [:default_level] = {} unless @logger.ancestors.include?(Urbivore::Logger) raise Urbivore::Exceptions::TypeError.new("MessagePacket expected a Logger") end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
instance methods
17 18 19 |
# File 'lib/urbivore/message_packet.rb', line 17 def logger @logger end |
Class Method Details
.logger(logger = nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/urbivore/message_packet.rb', line 6 def logger(logger = nil) if logger @logger = logger else @logger end end |
Instance Method Details
#message_collector(message_object) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/urbivore/message_packet.rb', line 28 def () # it may not matter... but keying these in a hash by level # seems like better design than putting them in a big pile # and using #select---if you generate a massive amount of debugging # info you don't want iterate over all of it just to generate a production # log message, right? [level] ||= [] # shit like this needs to be made threadsafe [level] << end |
#messages(requested = nil) ⇒ Object
39 40 41 42 |
# File 'lib/urbivore/message_packet.rb', line 39 def (requested = nil) # pull all desired levels and collate current_levels(requested).map { |level| @levels[level] }.flatten.sort end |
#submit ⇒ Object
send self to the logging machine
45 46 47 48 49 50 51 52 |
# File 'lib/urbivore/message_packet.rb', line 45 def submit if @submitted false else logger.submit(self) @submitted = true end end |
#submit! ⇒ Object
as above, but raise exception when trying to submit an already submitted log
56 57 58 59 60 61 62 |
# File 'lib/urbivore/message_packet.rb', line 56 def submit! if @submitted raise Urbivore::Exceptions::RuntimeError.new("MessagePacket already submitted") else submit end end |