Class: Pione::Agent::Logger

Inherits:
TupleSpaceClient show all
Defined in:
lib/pione/agent/logger.rb

Overview

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

Constant Summary

Constants included from Log::MessageLog

Log::MessageLog::MESSAGE_QUEUE

Instance Attribute Summary collapse

Attributes inherited from BasicAgent

#chain_threads

Instance Method Summary collapse

Methods inherited from TupleSpaceClient

#bye, #call_transition_method, #hello, #transit_to_init

Methods included from Log::MessageLog

#debug_message, #debug_message_begin, #debug_message_end, debug_mode, debug_mode=, debug_mode?, message, quiet_mode, quiet_mode=, quiet_mode?, #show, #user_message, #user_message_begin, #user_message_end

Methods included from TupleSpaceClientOperation

#base_location, #bye, #finalize, #hello, #notify_exception, #read, #take

Methods included from TupleSpace::TupleSpaceInterface

#process_log, #processing_error, #set_tuple_space, tuple_space_operation, #tuple_space_server, #with_process_log

Methods inherited from BasicAgent

agent_type, inherited, set_agent_type, #start, #start!, #states, #terminate, #terminated?, #transit, #wait_until, #wait_until_after, #wait_until_before, #wait_until_terminated

Methods included from StateTransitionSingletonMethod

#chain, #define_exception_handler, #define_transition, #exception_handler, #start, #transition_chain

Constructor Details

#initialize(tuple_space, location) ⇒ Logger

Create a logger agent.



12
13
14
15
16
17
# 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

Instance Attribute Details

#log_locationObject (readonly)

location of log file



8
9
10
# File 'lib/pione/agent/logger.rb', line 8

def log_location
  @log_location
end

#temporary_locationObject (readonly)

temporary location



9
10
11
# File 'lib/pione/agent/logger.rb', line 9

def temporary_location
  @temporary_location
end

Instance Method Details

#transit_to_recordObject

Record process_log tuples.



33
34
35
36
37
38
39
40
41
# 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_terminateObject

Copy from temporary location to log location.



44
45
46
47
48
49
50
51
52
53
54
55
# 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