multilog-collector 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This is a log collector for multilog of daemontools services.
4
4
 
5
+ == Install
6
+
7
+ sudo gem install multilog-collector
8
+
5
9
  == Usage
6
10
 
7
11
  Usage: multilog-collector [options]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,10 +5,13 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
5
5
  require 'djb/daemontools/multilog/collector'
6
6
 
7
7
  directory = "/service"
8
+ collector = Djb::Daemontools::Multilog::Collector.new
8
9
 
9
10
  opt = OptionParser.new
10
11
  opt.on('--help', 'show this message') { puts opt; exit }
11
- opt.on('-d DIR','--directory=DIR','service directory default: /service'){ |v| directory = v }
12
+ opt.on('-d DIR','--directory=DIR','service directory default: /service'){ |v| collector.directory = v }
13
+ opt.on('-l N','--lines=N','lines to collect default: 100'){ |v| collector.lines = v.to_i }
12
14
  opt.parse!(ARGV)
13
15
 
14
- puts Djb::Daemontools::Multilog::Collector.new(directory).collect
16
+ puts collector.collect
17
+
@@ -1,54 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
- # vim:set fileencoding=utf-8:
3
-
4
- require 'djb/tai64n'
2
+ # -*- coding: utf-8 -*-
3
+ require 'djb/daemontools/multilog/logs'
5
4
  module Djb
6
5
  module Daemontools
7
6
  module Multilog
8
- class Logs < Array
9
- def load(file)
10
- @file = file
11
- open(file) do |f|
12
- while line = f.gets
13
- self << Log.new(line,service)
14
- end
15
- end
16
- self
17
- end
18
-
19
- def service
20
- $1 if /\/([^\/]+)\/log\/main\/current/ =~ @file
21
- end
22
-
23
- def to_s
24
- join("\n",self)
25
- end
26
-
27
- end
28
-
29
- class Log
30
- def initialize(line,service)
31
- @line = line
32
- @service = service
33
- end
34
-
35
- def tai64n
36
- return $1 if /^(@[a-z0-9]+) / =~ @line
37
- end
38
-
39
- def time
40
- Tai64n::to_local(tai64n)
41
- end
42
-
43
- def to_s
44
- if /^(@[a-z0-9]+) (.*)/ =~ @line
45
- "%s [%s] %s" % [time.strftime("%Y-%m-%d %H:%M:%S"),@service,$2]
46
- end
47
- end
48
- end
49
-
50
7
  class Collector
8
+ attr_accessor :service_dir,:lines
9
+ alias directory= service_dir=
10
+
51
11
  def initialize(dir = "/service")
12
+ @lines = 100
52
13
  @service_dir = dir
53
14
  end
54
15
 
@@ -56,20 +17,19 @@ module Djb
56
17
  all = Logs.new
57
18
  glob_pattern = @service_dir + "/*/log/main/current"
58
19
  Dir.glob(glob_pattern).each do |file|
59
- all += Logs.new.load(file)
20
+ all += Logs.new.load(file,@lines)
60
21
  end
61
- all.sort do |a,b|
22
+ all.sort! do |a,b|
62
23
  a.time <=> b.time
63
24
  end
25
+ all[-@lines..-1]
64
26
  end
65
-
66
-
67
27
  end
68
28
 
69
29
  end
70
30
  end
71
31
  end
72
32
  =begin
73
- # collector = Djb::Daemontools::Multilog::Collector.new("/Users/tumf/service")
74
- # puts collector.collect
33
+ #collector = Djb::Daemontools::Multilog::Collector.new("/Users/tumf/service")
34
+ #puts collector.collect
75
35
  =end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'djb/tai64n'
4
+ module Djb
5
+ module Daemontools
6
+ module Multilog
7
+ class Log
8
+
9
+ def initialize(line,service)
10
+ @line = line
11
+ @service = service
12
+ end
13
+
14
+ def tai64n
15
+ return $1 if /^(@[a-z0-9]+) / =~ @line
16
+ end
17
+
18
+ def time
19
+ Tai64n::to_local(tai64n)
20
+ end
21
+
22
+ def to_s
23
+ if /^(@[a-z0-9]+) (.*)/ =~ @line
24
+ "%s [%s] %s" % [time.strftime("%Y-%m-%d %H:%M:%S"),@service,$2]
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'djb/daemontools/multilog/log'
4
+ module Djb
5
+ module Daemontools
6
+ module Multilog
7
+ class Logs < Array
8
+
9
+ def load(file,lines = nil)
10
+ @file = file
11
+ open(file) do |f|
12
+ n = 0
13
+ while line = f.gets
14
+ n += 1
15
+ self << Log.new(line,service)
16
+ break if lines and n >= lines
17
+ end
18
+ end
19
+ self
20
+ end
21
+
22
+ def service
23
+ $1 if /\/([^\/]+)\/log\/main\/current/ =~ @file
24
+ end
25
+
26
+ def to_s
27
+ join("\n",self)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{multilog-collector}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Yoshihiro TAKAHARA"]
12
+ s.date = %q{2011-01-16}
13
+ s.description = %q{This is a log collector for multilog of daemontools services.}
14
+ s.email = %q{y.takahara@gmail.com}
15
+ s.executables = ["multilog-collector.rb", "multilog-collector"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/multilog-collector",
27
+ "bin/multilog-collector.rb",
28
+ "lib/djb/daemontools/multilog/collector.rb",
29
+ "lib/djb/daemontools/multilog/log.rb",
30
+ "lib/djb/daemontools/multilog/logs.rb",
31
+ "lib/djb/tai64n.rb",
32
+ "lib/multilog-collector.rb",
33
+ "multilog-collector.gemspec",
34
+ "test/helper.rb",
35
+ "test/test_multilog-collector.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/tumf/multilog-collector}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.4.1}
41
+ s.summary = %q{log collector for multilog.}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_multilog-collector.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multilog-collector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yoshihiro TAKAHARA
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 +09:00
18
+ date: 2011-01-16 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -97,8 +97,11 @@ files:
97
97
  - bin/multilog-collector
98
98
  - bin/multilog-collector.rb
99
99
  - lib/djb/daemontools/multilog/collector.rb
100
+ - lib/djb/daemontools/multilog/log.rb
101
+ - lib/djb/daemontools/multilog/logs.rb
100
102
  - lib/djb/tai64n.rb
101
103
  - lib/multilog-collector.rb
104
+ - multilog-collector.gemspec
102
105
  - test/helper.rb
103
106
  - test/test_multilog-collector.rb
104
107
  has_rdoc: true