Class: Roby::EventLogging::AggregateEventLogger
- Defined in:
- lib/roby/event_logging/aggregate_event_logger.rb
Overview
An object that allows to dispatch logged events to multiple loggers
It is used by default by Plan and Roby::ExecutionEngine
Instance Method Summary collapse
-
#add(logger) ⇒ #dispose
Add a logger to the aggregate.
-
#clear ⇒ Array<EventLogger>
Remove all of the current loggers and return them.
- #close ⇒ Object
-
#dump(name, time, *args) ⇒ Object
Dump a normal log event.
- #dump_time ⇒ Object
-
#dump_timepoint(name, time, *args) ⇒ Object
Dump a timepoint.
- #flush_cycle(name, *args) ⇒ Object
-
#initialize ⇒ AggregateEventLogger
constructor
A new instance of AggregateEventLogger.
- #log_queue_size ⇒ Object
-
#log_timepoints? ⇒ Boolean
Whether timepoints should be logged at all.
-
#remove(logger) ⇒ Object
private
Remove the logger from the aggregate.
Constructor Details
#initialize ⇒ AggregateEventLogger
Returns a new instance of AggregateEventLogger.
9 10 11 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 9 def initialize @loggers = [] end |
Instance Method Details
#add(logger) ⇒ #dispose
Add a logger to the aggregate
16 17 18 19 20 21 22 23 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 16 def add(logger) @loggers << logger @log_timepoints ||= logger.log_timepoints? Roby.disposable do remove(logger) end end |
#clear ⇒ Array<EventLogger>
Remove all of the current loggers and return them
70 71 72 73 74 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 70 def clear current = @loggers.dup @loggers = [] current end |
#close ⇒ Object
51 52 53 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 51 def close @loggers.each(&:close) end |
#dump(name, time, *args) ⇒ Object
Dump a normal log event
42 43 44 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 42 def dump(name, time, *args) @loggers.each { |l| l.dump(name, time, *args) } end |
#dump_time ⇒ Object
59 60 61 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 59 def dump_time @loggers.sum(&:dump_time) end |
#dump_timepoint(name, time, *args) ⇒ Object
Dump a timepoint
47 48 49 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 47 def dump_timepoint(name, time, *args) @loggers.each { |l| l.dump_timepoint(name, time, *args) } end |
#flush_cycle(name, *args) ⇒ Object
63 64 65 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 63 def flush_cycle(name, *args) @loggers.each { _1.flush_cycle(name, *args) } end |
#log_queue_size ⇒ Object
55 56 57 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 55 def log_queue_size @loggers.map(&:log_queue_size).max end |
#log_timepoints? ⇒ Boolean
Whether timepoints should be logged at all
37 38 39 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 37 def log_timepoints? @log_timepoints end |
#remove(logger) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove the logger from the aggregate
Do not use this directly. Use the disposable returned from #add instead. This method's interface may change without notice
31 32 33 34 |
# File 'lib/roby/event_logging/aggregate_event_logger.rb', line 31 def remove(logger) @loggers.delete(logger) @log_timepoints = @loggers.any?(&:log_timepoints?) end |