Class: Backstage::Log
Constant Summary
collapse
- LOG_GLOB =
"*log"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Resource
#association_chain, #available_actions, included, #resource, #to_hash
Constructor Details
#initialize(file_path) ⇒ Log
Returns a new instance of Log.
40
41
42
|
# File 'lib/logs/models/log.rb', line 40
def initialize(file_path)
@file_path = file_path
end
|
Instance Attribute Details
#file_path ⇒ Object
Also known as:
full_name
Returns the value of attribute file_path.
21
22
23
|
# File 'lib/logs/models/log.rb', line 21
def file_path
@file_path
end
|
Class Method Details
.all(log_dir = nil) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/logs/models/log.rb', line 30
def all(log_dir = nil)
log_dir ||= Backstage.jboss_log_dir
Dir.glob("#{log_dir}/#{LOG_GLOB}").collect do |path|
Log.new( File.expand_path( path ) )
end.sort_by(&:name)
end
|
.to_hash_attributes ⇒ Object
26
27
28
|
# File 'lib/logs/models/log.rb', line 26
def to_hash_attributes
super + [:name, :file_path, :size]
end
|
Instance Method Details
46
47
48
|
# File 'lib/logs/models/log.rb', line 46
def name
File.basename( file_path )
end
|
50
51
52
|
# File 'lib/logs/models/log.rb', line 50
def size
File.size( file_path )
end
|
#tail(options) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/logs/models/log.rb', line 54
def tail(options)
offset = (options['offset'] || -1000).to_i
File.open(@file_path, 'r') do |file|
if offset.abs > file.stat.size
offset = offset < 0 ? 0 : file.stat.size
end
if offset < 0
file.seek(offset, IO::SEEK_END)
file.readline else
file.seek(offset)
end
lines = []
until file.eof? do
lines << file.readline
end
offset = file.pos
{ :offset => offset, :lines => lines.compact }
end
end
|