class Pione::Agent::Logger

Logger is an agent for logging process events like agent activity or rule process.

Attributes

log_location[R]
temporary_location[R]

Public Class Methods

new(tuple_space, location) click to toggle source

Create a logger agent.

Calls superclass method
# File lib/pione/agent/logger.rb, line 12
def initialize(tuple_space, location)
  super(tuple_space)
  @log_id = Time.now.iso8601(3)
  @log_location = location.directory? ? location + "pione-process.log" : location
  @temporary_location = get_temporary_location
end

Public Instance Methods

transit_to_record() click to toggle source

Record process_log tuples.

# File lib/pione/agent/logger.rb, line 33
def transit_to_record
  begin
    write_records(take_all(TupleSpace::ProcessLogTuple.any))
  rescue => e
    # logger is terminated at last in termination processes, so tuple space may be closed
    Log::SystemLog.warn("logger agent failed to take process logs: %s" % e.message)
    terminate
  end
end
transit_to_terminate() click to toggle source

Copy from temporary location to log location.

Calls superclass method
# File lib/pione/agent/logger.rb, line 44
def transit_to_terminate
  begin
    write_records(take_all!(TupleSpace::ProcessLogTuple.any))
  rescue => e
    # logger is terminated at last in termination processes, so tuple space may be closed
    Log::SystemLog.warn("logger agent failed to take process logs.", self, e)
  end
  if @log_location != @temporary_location
    @temporary_location.copy(@log_location)
  end
  super
end

Private Instance Methods

get_temporary_location() click to toggle source

Get the temporary location. If the log location doesn’t suport append writing, output location is in local filesystem.

# File lib/pione/agent/logger.rb, line 72
def get_temporary_location
  if @log_location.real_appendable?
    @log_location
  else
    Location[Temppath.mkdir + @log_location.basename]
  end
end
write_records(tuples) click to toggle source

Write records with sorting.

# File lib/pione/agent/logger.rb, line 64
def write_records(tuples)
  tuples.sort{|a,b| a.timestamp <=> b.timestamp}.each do |tuple|
    @temporary_location.append tuple.message.format(@log_id) + "\n"
  end
end