5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/colortail/application.rb', line 5
def run!(*arguments)
opt = ColorTail::Options.new(arguments)
files = opt[:files]
options = opt[:options]
if options[:invalid_argument]
$stderr.puts options[:invalid_argument]
options[:help] = true
end
if options[:help]
$stderr.puts opt.opts
return 1
end
begin
if File.exists?(options[:conf])
config = ColorTail::Configuration.new(options[:conf])
@match_group = config.load_opts(options[:group])
else
@match_group = Array.push( 'default' => [] )
end
if options[:list]
config.display_match_groups()
return 1
end
logger = ColorTail::Colorize.new()
if @match_group.class == Array
@match_group.each do |matcher|
logger.add_color_matcher( matcher )
end
else
logger.add_color_matcher( @match_group )
end
threads = []
files.each do |file|
threads[files.index(file)] = Thread.new {
tailer = ColorTail::TailFile.new( file )
tailer.interval = 10
tailer.backward( 10 )
tailer.tail { |line| logger.log( file, line ) }
}
threads[files.index(file)].run
end
threads.each do |thread|
thread.join
end
rescue Interrupt
cleanup(threads)
end
return 0
end
|