Class: Pione::Log::ProcessLog
- Inherits:
-
Object
- Object
- Pione::Log::ProcessLog
- Defined in:
- lib/pione/log/process-log.rb
Overview
ProcessLog represents process log file.
Direct Known Subclasses
Class Attribute Summary collapse
-
.filter_block ⇒ Object
readonly
Returns the value of attribute filter_block.
Instance Attribute Summary collapse
-
#records ⇒ Array<ProcessRcord>
readonly
Records of the log.
Class Method Summary collapse
-
.[](name) ⇒ Object
Return the named formatter class.
-
.group_by(key, records) ⇒ Object
Return the record table grouped by the key.
-
.known?(name) ⇒ Boolean
Return true if the formatter name is known.
-
.read(location) ⇒ Object
Read the raw log file and return the process log table grouped by log id.
-
.set_filter(&block) ⇒ Object
Set record filter.
-
.set_format_name(name) ⇒ void
Set formatter name of this class.
Instance Method Summary collapse
-
#format(trace_filters = []) ⇒ String
Format records.
-
#group_by(key) ⇒ Hash{String => Array<ProcessRecord>}
Return the record table grouped by the key.
-
#initialize(records) ⇒ ProcessLog
constructor
A new instance of ProcessLog.
Constructor Details
#initialize(records) ⇒ ProcessLog
Returns a new instance of ProcessLog.
74 75 76 77 78 79 80 81 82 |
# File 'lib/pione/log/process-log.rb', line 74 def initialize(records) @records = records.select do |record| if block = self.class.filter_block block.call(record) else true end end end |
Class Attribute Details
.filter_block ⇒ Object (readonly)
Returns the value of attribute filter_block.
55 56 57 |
# File 'lib/pione/log/process-log.rb', line 55 def filter_block @filter_block end |
Instance Attribute Details
#records ⇒ Array<ProcessRcord> (readonly)
Returns records of the log.
70 71 72 |
# File 'lib/pione/log/process-log.rb', line 70 def records @records end |
Class Method Details
.[](name) ⇒ Object
Return the named formatter class.
24 25 26 |
# File 'lib/pione/log/process-log.rb', line 24 def [](name) ProcessLog.instance_variable_get(:@format)[name] end |
.group_by(key, records) ⇒ Object
Return the record table grouped by the key.
58 59 60 61 62 63 |
# File 'lib/pione/log/process-log.rb', line 58 def group_by(key, records) records.inject({}) do |table, record| table[record.send(key)] ||= [] table.tap {|x| x[record.send(key)] << record} end end |
.known?(name) ⇒ Boolean
Return true if the formatter name is known.
19 20 21 |
# File 'lib/pione/log/process-log.rb', line 19 def known?(name) ProcessLog.instance_variable_get(:@format).has_key?(name) end |
.read(location) ⇒ Object
Read the raw log file and return the process log table grouped by log id.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pione/log/process-log.rb', line 29 def read(location) # create local cache of raw log for performance cache = location unless location.scheme == "local" cache = Location[Temppath.create] cache.create(location.read) end # read all records records = cache.path.each_line.map do |line| JSON.parse(line).inject({}) do |data, (key, val)| data.tap {data[key.to_sym] = val} end.tap {|data| break ProcessRecord.build(data)} end # group records by log id group_by(:log_id, records).inject({}) do |table, (key, _records)| table.tap {table[key] = new(_records)} end end |
.set_filter(&block) ⇒ Object
Set record filter.
51 52 53 |
# File 'lib/pione/log/process-log.rb', line 51 def set_filter(&block) @filter_block = block end |
.set_format_name(name) ⇒ void
This method returns an undefined value.
Set formatter name of this class.
14 15 16 |
# File 'lib/pione/log/process-log.rb', line 14 def set_format_name(name) ProcessLog.instance_variable_get(:@format)[name] = self end |
Instance Method Details
#format(trace_filters = []) ⇒ String
Format records.
96 97 98 |
# File 'lib/pione/log/process-log.rb', line 96 def format(trace_filters=[]) raise NotImplementedError end |
#group_by(key) ⇒ Hash{String => Array<ProcessRecord>}
Return the record table grouped by the key.
88 89 90 |
# File 'lib/pione/log/process-log.rb', line 88 def group_by(key) self.class.group_by(key, @records) end |