logworm_client 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,9 @@
1
- v0.3.2 added lw_log method
1
+ v0.4.0 Added support for running on Rails!
2
+ To use, add config.gem ‘logworm_client’ to environment.rb
3
+ Then you can configure in ApplicationController, via logs_requests [:short | :long]+
4
+ Works from views, models, or controllers.
5
+
6
+ v0.3.2 added lw_log method --fixed small issue
2
7
 
3
8
  v0.3.1 added lw_log method
4
9
 
data/Manifest CHANGED
@@ -8,6 +8,7 @@ bin/lw-tail
8
8
  lib/logworm_client.rb
9
9
  lib/logworm_client/logger.rb
10
10
  lib/logworm_client/rack.rb
11
+ lib/logworm_client/rails.rb
11
12
  lib/logworm_utils.rb
12
13
  lib/logworm_utils/compute.rb
13
14
  lib/logworm_utils/heroku.rb
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'echoe'
2
- Echoe.new('logworm_client', '0.3.2') do |p|
2
+ Echoe.new('logworm_client', '0.4.0') do |p|
3
3
  p.description = "logworm client utilities"
4
4
  p.url = "http://www.logworm.com"
5
5
  p.author = "Pomelo, LLC"
data/bin/lw-tail CHANGED
@@ -4,6 +4,12 @@ require 'rubygems'
4
4
  require 'logworm_utils'
5
5
  require 'optparse'
6
6
 
7
+ def help(option_parser)
8
+ puts option_parser.help
9
+ puts
10
+ LogwormTail.list
11
+ end
12
+
7
13
  options = {
8
14
  :limit => 200,
9
15
  :loop => false,
@@ -54,7 +60,7 @@ option_parser = OptionParser.new do |opts|
54
60
  end
55
61
 
56
62
  opts.on( '-h', '--help', 'Display this screen' ) do
57
- puts option_parser.help
63
+ help option_parser
58
64
  exit(1)
59
65
  end
60
66
 
@@ -64,7 +70,7 @@ end
64
70
  option_parser.parse!
65
71
  table = ARGV.pop
66
72
  if !table
67
- puts option_parser.help
73
+ help option_parser
68
74
  exit(1)
69
75
  end
70
76
  table.strip!
@@ -2,6 +2,7 @@ require 'logworm'
2
2
 
3
3
  require 'logworm_client/logger'
4
4
  require 'logworm_client/rack'
5
+ require 'logworm_client/rails'
5
6
 
6
7
  def lw_log (logname, values)
7
8
  Logworm::Logger.log(logname, values)
@@ -0,0 +1,70 @@
1
+ ###
2
+ # Extemds ActionController::Base and aliases the process method, to wrap it with the standard logworm request cycle
3
+ #
4
+ # By default it will automatically log web requests (in a short format) into web_log
5
+ # Can also log in long format if specified.
6
+ #
7
+ # Configuration
8
+ # In ApplicationController, add
9
+ # logs_requests :short, :long
10
+ # logs_requests :long
11
+ # logs_requests :short, :long
12
+ ###
13
+ if defined?(ActionController)
14
+
15
+ ActionController::Base.class_eval do
16
+ @@log_requests_short = true
17
+ @@log_requests_long = false
18
+
19
+ def self.logs_requests(*options)
20
+ @@log_requests_short = (options.include?(:short) or options.include?("short"))
21
+ @@log_requests_long = (options.include?(:long) or options.include?("long"))
22
+ end
23
+
24
+ def process_with_logworm_log(request, response, method = :perform_action, *arguments)
25
+ startTime = Time.now
26
+ Logworm::Logger.start_cycle
27
+ begin
28
+ response = process_without_logworm_log(request, response, method, *arguments)
29
+ appTime = (Time.now - startTime)
30
+ ensure
31
+ env = request.env
32
+ status = response.status[0..2]
33
+
34
+ Logworm::Logger.log(:web_log_long,
35
+ {:summary => "#{env['REQUEST_METHOD']} #{env['REQUEST_URI']} - #{status} #{appTime}",
36
+ :request => env_to_log(env).merge({:input => request.request_parameters}),
37
+ :response => {:status => status, :headers => response.headers},
38
+ :profiling => appTime}) if @@log_requests_long
39
+ Logworm::Logger.log(:web_log,
40
+ {:summary => "#{env['REQUEST_METHOD']} #{env['REQUEST_URI']} - #{status} #{appTime}",
41
+ :request_path => env['REQUEST_URI'], :request_ip => env['REMOTE_ADDR'],
42
+ :request_method => env['REQUEST_METHOD'],
43
+ :input => request.request_parameters,
44
+ :response_status => status,
45
+ :profiling => appTime}) if @@log_requests_short
46
+ begin
47
+ Timeout::timeout(1) {
48
+ Logworm::Logger.flush # Flushes only if there are any entries. Times out after a second
49
+ }
50
+ rescue Exception => e
51
+ # Ignore --nothing we can do
52
+ # The list of logs may (and most likely will) be preserved for the next request
53
+ logger.error("logworm call failed: #{e}") if logger
54
+ end
55
+ return response
56
+ end
57
+ end
58
+
59
+ def env_to_log(env)
60
+ to_log = {}
61
+ env.each do |k,v|
62
+ to_log[k.to_s.downcase.to_sym] = v unless (k.to_s =~ /rack/i or k.to_s =~ /\./i)
63
+ end
64
+ end
65
+
66
+ alias_method_chain :process, :logworm_log
67
+ end
68
+
69
+ end
70
+
@@ -12,6 +12,24 @@ class LogwormTail
12
12
  end
13
13
  end
14
14
 
15
+ def self.list
16
+ begin
17
+ @db = Logworm::DB.new(false)
18
+ @tables = @db.tables
19
+ if @tables and @tables.size > 0
20
+ puts "The following are the tables that you've created thus far:"
21
+ @tables.sort {|x,y| x["tablename"] <=> y["tablename"]}.each do |t|
22
+ puts "\t - #{t["tablename"]}, #{t["rows"]} rows, last updated on #{date_time(t["last_write"])}"
23
+ end
24
+ else
25
+ puts "You haven't recorded any data yet."
26
+ end
27
+ rescue Exception => e
28
+ $stderr.puts "Error: #{e}"
29
+ exit(-1)
30
+ end
31
+ end
32
+
15
33
  def run
16
34
  # Create a resource for the query
17
35
  begin
@@ -56,6 +74,10 @@ class LogwormTail
56
74
 
57
75
  private
58
76
 
77
+ def self.date_time(val)
78
+ val.gsub(/T/, ' @ ').gsub(/Z/, ' GMT')
79
+ end
80
+
59
81
  def print_rows(rows, last)
60
82
  last = "" if last.nil?
61
83
  rows.reverse.each do |r|
@@ -64,7 +86,7 @@ class LogwormTail
64
86
  last = r["_ts"]
65
87
  r.delete("_id") unless @options[:fields].include?("_id")
66
88
  r.delete("_ts") unless @options[:fields].include?("_ts")
67
- puts "#{last.gsub(/T/, ' @ ').gsub(/Z/, ' GMT')} ==> "
89
+ puts "#{LogwormTail.date_time(last)} ==> "
68
90
  print_row(r)
69
91
  end
70
92
  end
@@ -73,7 +95,7 @@ class LogwormTail
73
95
 
74
96
  def print_row(r)
75
97
  if @options[:flat]
76
- r.keys.sort.map {|k| "#{k}: #{r[k].inspect}"}.join(', ')
98
+ puts "\t" + r.keys.sort.map {|k| "#{k}: #{r[k].inspect}"}.join(', ')
77
99
  else
78
100
  r.keys.sort.each do |k|
79
101
  puts "\t#{k}: #{r[k].inspect}"
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{logworm_client}
5
- s.version = "0.3.2"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pomelo, LLC"]
9
- s.date = %q{2010-03-02}
9
+ s.date = %q{2010-03-04}
10
10
  s.description = %q{logworm client utilities}
11
11
  s.email = %q{schapira@pomelollc.com}
12
12
  s.executables = ["lw-compute", "lw-heroku", "lw-tail"]
13
- s.extra_rdoc_files = ["CHANGELOG", "README", "bin/lw-compute", "bin/lw-heroku", "bin/lw-tail", "lib/logworm_client.rb", "lib/logworm_client/logger.rb", "lib/logworm_client/rack.rb", "lib/logworm_utils.rb", "lib/logworm_utils/compute.rb", "lib/logworm_utils/heroku.rb", "lib/logworm_utils/tail.rb"]
14
- s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "bin/lw-compute", "bin/lw-heroku", "bin/lw-tail", "lib/logworm_client.rb", "lib/logworm_client/logger.rb", "lib/logworm_client/rack.rb", "lib/logworm_utils.rb", "lib/logworm_utils/compute.rb", "lib/logworm_utils/heroku.rb", "lib/logworm_utils/tail.rb", "logworm_client.gemspec"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "README", "bin/lw-compute", "bin/lw-heroku", "bin/lw-tail", "lib/logworm_client.rb", "lib/logworm_client/logger.rb", "lib/logworm_client/rack.rb", "lib/logworm_client/rails.rb", "lib/logworm_utils.rb", "lib/logworm_utils/compute.rb", "lib/logworm_utils/heroku.rb", "lib/logworm_utils/tail.rb"]
14
+ s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "bin/lw-compute", "bin/lw-heroku", "bin/lw-tail", "lib/logworm_client.rb", "lib/logworm_client/logger.rb", "lib/logworm_client/rack.rb", "lib/logworm_client/rails.rb", "lib/logworm_utils.rb", "lib/logworm_utils/compute.rb", "lib/logworm_utils/heroku.rb", "lib/logworm_utils/tail.rb", "logworm_client.gemspec"]
15
15
  s.homepage = %q{http://www.logworm.com}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Logworm_client", "--main", "README"]
17
17
  s.require_paths = ["lib"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 2
9
- version: 0.3.2
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pomelo, LLC
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-02 00:00:00 -05:00
17
+ date: 2010-03-04 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ extra_rdoc_files:
82
82
  - lib/logworm_client.rb
83
83
  - lib/logworm_client/logger.rb
84
84
  - lib/logworm_client/rack.rb
85
+ - lib/logworm_client/rails.rb
85
86
  - lib/logworm_utils.rb
86
87
  - lib/logworm_utils/compute.rb
87
88
  - lib/logworm_utils/heroku.rb
@@ -97,6 +98,7 @@ files:
97
98
  - lib/logworm_client.rb
98
99
  - lib/logworm_client/logger.rb
99
100
  - lib/logworm_client/rack.rb
101
+ - lib/logworm_client/rails.rb
100
102
  - lib/logworm_utils.rb
101
103
  - lib/logworm_utils/compute.rb
102
104
  - lib/logworm_utils/heroku.rb