logworm_amqp 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ v0.9.7
2
+ - lw_query now accepts a TTL parameter -- 300 seconds by default, can be lowered up to 20 seconds min
3
+ - lw-compute now has a standard TTL of 60 seconds
4
+ - no longer preserves entries from one request to the other --made more sense when there were timeouts, but with AMQP we don't
5
+ expect to see so many of them. Fixes bugs with log_with_request calls as well.
6
+ - Adds a new optional field in the web_log table, :apache_log, a string with information about the HTTP request in
7
+ the regular Apache Log format (requested by Dave Brwon @ Top Prospect)
8
+
1
9
  v0.9.6
2
10
  - Preserves the order of desired fields in a query.
3
11
  - Handled an exception which was being thrown when the connection to the server could not be established.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'echoe'
2
- Echoe.new('logworm_amqp', '0.9.6') do |p|
2
+ Echoe.new('logworm_amqp', '0.9.7') do |p|
3
3
  p.description = "logworm - logging service"
4
4
  p.url = "http://www.logworm.com"
5
5
  p.author = "Pomelo, LLC"
data/lib/base/db.rb CHANGED
@@ -87,8 +87,10 @@ module Logworm
87
87
  db_call(:get, "#{host_with_protocol}/") || []
88
88
  end
89
89
 
90
- def query(table, cond)
91
- db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
90
+ def query(table, cond, ttl = nil)
91
+ ttl = nil if ttl and !ttl.is_a? Fixnum
92
+ ttl = 20 if ttl and ttl.to_i > 0 and ttl.to_i < 20
93
+ db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond, :ttl => ttl})
92
94
  end
93
95
 
94
96
 
data/lib/client/logger.rb CHANGED
@@ -34,6 +34,8 @@ module Logworm
34
34
  ###
35
35
  def self.start_cycle
36
36
  $request_id = "#{Thread.current.object_id}-#{(Time.now.utc.to_f * 1000).to_i}"
37
+ $lr_queue = []
38
+ $attaches = {}
37
39
  end
38
40
 
39
41
  ###
@@ -87,7 +89,6 @@ module Logworm
87
89
  # Return if no server
88
90
  unless $lw_server
89
91
  $stderr.puts "\t logworm not configured. #{to_send} entries dropped."
90
- $lr_queue = []
91
92
  return [0,0]
92
93
  end
93
94
 
@@ -99,12 +100,23 @@ module Logworm
99
100
 
100
101
  startTime = Time.now
101
102
  $lw_server.batch_log($lr_queue.to_json)
102
- $lr_queue = []
103
103
  endTime = Time.now
104
104
 
105
105
  [to_send, (endTime - startTime)]
106
106
  end
107
107
 
108
+ ###
109
+ # Utility function
110
+ ###
111
+ def self.apache_log(ip, method, path, env, status, response_headers)
112
+ if response_headers['Content-Length']
113
+ response_length = response_headers['Content-Length'].to_s == '0' ? '-' : response_headers['Content-Length']
114
+ else
115
+ response_length = "-"
116
+ end
117
+ "#{ip} - #{env["REMOTE_USER"] || "-"} [#{Time.now.strftime("%d/%b/%Y:%H:%M:%S %z")}] \"#{method} #{path} #{env['HTTP_VERSION']}\" #{status} #{response_length} \"#{env['HTTP_REFERER']}\" \"#{env['HTTP_USER_AGENT']}\""
118
+ end
119
+
108
120
  private
109
121
  # Turn keys into symbols, delete empty ones, rename conflicting ones
110
122
  def self.cleanup(values)
data/lib/client/rack.rb CHANGED
@@ -8,6 +8,7 @@ module Logworm
8
8
 
9
9
  @log_requests = (options[:donot_log_requests].nil? or options[:donot_log_requests] != true)
10
10
  @log_headers = (options[:log_headers] and options[:log_headers] == true)
11
+ @log_apache = (options[:log_apache] and options[:log_apache] == true)
11
12
  @log_envs = options[:log_environments] || ["production"]
12
13
  @log_envs << "development" if (options[:log_in_development] and options[:log_in_development] == true) # backwards compatibility
13
14
  Logger.use_default_db
@@ -44,8 +45,9 @@ module Logworm
44
45
  :response_status => status,
45
46
  :profiling => appTime,
46
47
  :queue_size => queue_size}
47
- entry[:request_headers] = http_headers if @log_headers
48
+ entry[:request_headers] = http_headers if @log_headers
48
49
  entry[:response_headers] = response_headers if @log_headers
50
+ entry[:apache_log] = Logger.apache_log(ip, method, path, env, status, response_headers) if @log_apache
49
51
  Logger.log(:web_log, entry) if @log_requests
50
52
 
51
53
  begin
@@ -54,7 +56,7 @@ module Logworm
54
56
  }
55
57
  rescue Exception => e
56
58
  # Ignore --nothing we can do. The list of logs may (and most likely will) be preserved for the next request
57
- env['rack.errors'].puts("logworm call failed: #{e}")
59
+ $stderr.puts("logworm call failed: #{e}")
58
60
  end
59
61
  end
60
62
 
data/lib/client/rails.rb CHANGED
@@ -12,6 +12,7 @@ if defined?(ActionController) and Rails::VERSION::STRING and Rails::VERSION::STR
12
12
  ## Basic settings: log requests, without headers. Use default db, and timeout after 1 second
13
13
  @@log_requests = true
14
14
  @@log_headers = false
15
+ @@log_apache = false
15
16
  @@log_envs = ["production"]
16
17
  @@timeout = (RAILS_ENV == 'production' ? 1 : 5)
17
18
  Logworm::Logger.use_default_db
@@ -39,6 +40,15 @@ if defined?(ActionController) and Rails::VERSION::STRING and Rails::VERSION::STR
39
40
  @@log_envs << "development"
40
41
  end
41
42
 
43
+ ###
44
+ # Log a field with Apache common log
45
+ # Use from ApplicationController
46
+ ###
47
+ def self.log_apache
48
+ @@log_apache = true
49
+ end
50
+
51
+
42
52
  def self.log_environments(*envs)
43
53
  @@log_envs = envs
44
54
  end
@@ -80,8 +90,9 @@ if defined?(ActionController) and Rails::VERSION::STRING and Rails::VERSION::STR
80
90
  :response_status => status,
81
91
  :profiling => appTime,
82
92
  :queue_size => queue_size}
83
- entry[:request_headers] = http_headers if @@log_headers
93
+ entry[:request_headers] = http_headers if @@log_headers
84
94
  entry[:response_headers] = response.headers if @@log_headers
95
+ entry[:apache_log] = Logworm::Logger.apache_log(ip, method, path, request.env, status, response.headers) if @@log_apache
85
96
  Logworm::Logger.log(:web_log, entry) if @@log_requests
86
97
 
87
98
  begin
data/lib/cmd/compute.rb CHANGED
@@ -21,9 +21,9 @@ class LogwormCompute
21
21
  def run
22
22
  # Create a resource for the query
23
23
  begin
24
- query_data = @db.query(@table, @query.to_json)
24
+ query_data = @db.query(@table, @query.to_json, 60) # 60 second ttl by default
25
25
  url = query_data["results_uri"]
26
- rows = @db.results(url + "?nocache=1")["results"]
26
+ rows = @db.results(url)["results"]
27
27
  rescue Logworm::DatabaseException, Logworm::ForbiddenAccessException => e
28
28
  $stderr.puts "Error: #{e}"
29
29
  exit(-1)
data/lib/logworm_amqp.rb CHANGED
@@ -46,10 +46,10 @@ alias :log_with_request :lw_with_log
46
46
  # raises Logworm::DatabaseException, Logworm::ForbiddenAccessException, Logworm::InvalidQueryException
47
47
  # or just a regular Exception if it cannot find the URL to the logging database
48
48
  ###
49
- def lw_query(logname, query = {})
49
+ def lw_query(logname, query = {}, ttl = nil)
50
50
  db = Logworm::DB.from_config_or_die # Establish connection to DB
51
51
  query = Logworm::QueryBuilder.new(query).to_json if query.is_a? Hash # Turn query into proper JSON string
52
- query_data = db.query(logname, query) # POST to create query
52
+ query_data = db.query(logname, query, ttl) # POST to create query
53
53
  db.results(query_data["results_uri"]) # GET from query's results uri
54
54
  end
55
55
 
data/logworm_amqp.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{logworm_amqp}
5
- s.version = "0.9.6"
5
+ s.version = "0.9.7"
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-08-24}
9
+ s.date = %q{2010-09-03}
10
10
  s.description = %q{logworm - logging service}
11
11
  s.email = %q{schapira@pomelollc.com}
12
12
  s.executables = ["lw-compute", "lw-tail"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logworm_amqp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pomelo, LLC
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 -04:00
18
+ date: 2010-09-03 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency