log_weasel 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_weasel (0.0.5)
4
+ log_weasel (0.0.6)
5
5
  activesupport (~> 3.0)
6
6
 
7
7
  GEM
@@ -45,7 +45,6 @@ PLATFORMS
45
45
  ruby
46
46
 
47
47
  DEPENDENCIES
48
- activesupport (~> 3.0)
49
48
  hoptoad_notifier
50
49
  log_weasel!
51
50
  mocha
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Log Weasel
2
2
 
3
- Instrument Rails and Resque with shared transaction IDs so that you trace execution of a unit of work across
3
+ Instrument Rails and Resque with shared transaction IDs to trace execution of a unit of work across
4
4
  applications and application instances.
5
+
5
6
  This particularly handy if you're using a system like <a href="http://www.splunk.com">Splunk</a> to manage your log
6
7
  files across many applications and application instances.
7
8
 
@@ -19,16 +20,31 @@ Use bundler to install it:
19
20
  bundle install
20
21
  </pre>
21
22
 
23
+ ## Configure
24
+
25
+ In your application initialization (e.g. config/initializers/log_weasel.rb) load and configure Log Weasel with:
26
+
27
+ <pre>
28
+ LogWeasel.configure do |config|
29
+ config.key = "YOUR_APP"
30
+ end
31
+ <pre>
32
+
33
+ <code>key</code> is a string that will be included in your transaction IDs and is particularly
34
+ useful in an environment where a unit of work may span multiple applications.
35
+
22
36
  ## Rack
23
37
 
24
- Log Weasel provides Rack middleware to create and destroy a transaction for every HTTP request. You can use it
25
- in a any web framework that supports Rack (Rails, Sinatra,...)
38
+ Log Weasel provides Rack middleware to create and destroy a transaction ID for every HTTP request. You can use it
39
+ in a any web framework that supports Rack (Rails, Sinatra,...) by using <code>LogWeasel::Middleware</code> in your middleware
40
+ stack.
26
41
 
27
42
  ### Rails 3
28
43
 
29
- To see Log Weasel transaction IDs in your Rails logs, you need to add the Rack middleware and
30
- either use the BufferedLogger provided or customize the formatting of your logger to include
31
- <code>LogWeasel::Transaction.id</code>.
44
+ For Rails 3, we provide a Railtie that automatically registers the Rack middleware.
45
+
46
+ All you need to see Log Weasel transaction IDs in your Rails logs is to either use the BufferedLogger provided or
47
+ customize the formatting of your logger to include <code>LogWeasel::Transaction.id</code>.
32
48
 
33
49
  <pre>
34
50
  YourApp::Application.configure do
@@ -36,22 +52,12 @@ YourApp::Application.configure do
36
52
  config.logger = logger
37
53
  config.action_controller.logger = logger
38
54
  config.active_record.logger = logger
39
-
40
- config.middleware.insert_before Rails::Rack::Logger,
41
- LogWeasel::Middleware, :key => 'YOUR_APP'
42
55
  end
43
56
  </pre>
44
57
 
45
- <code>:key</code> is an optional parameter that is useful in an environment where a unit of work may span multiple applications.
46
-
47
58
  ## Resque
48
59
 
49
- To see Log Weasel transaction IDs in your Resque logs, you need to need to initialize Log Weasel
50
- when you configure Resque, for example in a Rails initializer.
51
-
52
- <pre>
53
- LogWeasel::Resque.initialize! :key => 'YOUR_APP'
54
- </pre>
60
+ When you configure Log Weasel as described above, it modifies Resque to include transaction IDs in all worker logs.
55
61
 
56
62
  Start your Resque worker with <code>VERBOSE=1</code> and you'll see transaction IDs in your Resque logs.
57
63
 
@@ -121,6 +127,18 @@ and our development log shows:
121
127
  [2011-02-14 14:37:10] YOUR_APP-RESQUE-a8e54bfb76718d09f8ed 48453 INFO EchoJob.perform: "hi from Rails console"
122
128
  </pre>
123
129
 
130
+ and our resque log shows:
131
+
132
+ <pre>
133
+ *** got: (Job{default_queue} | EchoJob | ["hello from HelloController"] | {"log_weasel_id"=>"SAMPLE_APP-WEB-a65e45476ff2f5720e23"})
134
+ *** Running after_fork hook with [(Job{default_queue} | EchoJob | ["hello from HelloController"] | {"log_weasel_id"=>"SAMPLE_APP-WEB-a65e45476ff2f5720e23"})]
135
+ *** SAMPLE_APP-WEB-a65e45476ff2f5720e23 done: (Job{default_queue} | EchoJob | ["hello from HelloController"] | {"log_weasel_id"=>"SAMPLE_APP-WEB-a65e45476ff2f5720e23"})
136
+
137
+ *** got: (Job{default_queue} | EchoJob | ["hi from Rails console"] | {"log_weasel_id"=>"SAMPLE_APP-RESQUE-00919a012476121cf89c"})
138
+ *** Running after_fork hook with [(Job{default_queue} | EchoJob | ["hi from Rails console"] | {"log_weasel_id"=>"SAMPLE_APP-RESQUE-00919a012476121cf89c"})]
139
+ *** SAMPLE_APP-RESQUE-00919a012476121cf89c done: (Job{default_queue} | EchoJob | ["hi from Rails console"] | {"log_weasel_id"=>"SAMPLE_APP-RESQUE-00919a012476121cf89c"})
140
+ </pre>
141
+
124
142
  Units of work initiated from Resque, for example if using a scheduler like
125
143
  <a href="https://github.com/bvandenbos/resque-scheduler">resque-scheduler</a>,
126
144
  will include 'RESQUE' in the transaction ID to indicate that the work started in Resque.
@@ -131,6 +149,9 @@ If you would like to contribute a fix or integrate Log Weasel transaction tracki
131
149
  please fork the code, add the fix or feature in your local project and then send a pull request on github.
132
150
  Please ensure that you include a test which verifies your changes.
133
151
 
152
+ ## Authors
153
+
154
+ <a href="http://github.com/asalant">Alon Salant</a> and <a href="http://github.com/brettfishman">Brett Fishman</a>.
134
155
 
135
156
  ## LICENSE
136
157
 
@@ -1,7 +1,7 @@
1
1
  class LogWeasel::Middleware
2
2
  def initialize(app, options = {})
3
3
  @app = app
4
- @key = options[:key] ? "#{options[:key]}-WEB" : "WEB"
4
+ @key = LogWeasel.config.key ? "#{LogWeasel.config.key}-WEB" : "WEB"
5
5
  end
6
6
 
7
7
  def call(env)
@@ -0,0 +1,5 @@
1
+ require 'rails'
2
+
3
+ class LogWeasel::Railtie < Rails::Railtie
4
+ config.app_middleware.insert_before "::Rails::Rack::Logger", "LogWeasel::Middleware"
5
+ end
@@ -5,7 +5,7 @@ module LogWeasel::Resque
5
5
  ::Resque::Job.send(:include, LogWeasel::Resque::Job)
6
6
  ::Resque.extend(LogWeasel::Resque::ClassMethods)
7
7
 
8
- key = options[:key] ? "#{options[:key]}-RESQUE" : "RESQUE"
8
+ key = LogWeasel.config.key ? "#{LogWeasel.config.key}-RESQUE" : "RESQUE"
9
9
 
10
10
  ::Resque.after_fork do |job|
11
11
  LogWeasel::Resque::Callbacks.after_fork job, key
@@ -1,5 +1,5 @@
1
1
  module Log
2
2
  module Weasel
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
data/lib/log_weasel.rb CHANGED
@@ -3,8 +3,32 @@ require 'log_weasel/buffered_logger'
3
3
  require 'log_weasel/hoptoad_notifier'
4
4
  require 'log_weasel/middleware'
5
5
  require 'log_weasel/resque'
6
+ require 'log_weasel/railtie' if defined? ::Rails::Railtie
6
7
 
7
- class << ::HoptoadNotifier
8
- include LogWeasel::HoptoadNotifier;
9
- end if defined? ::HoptoadNotifier
10
8
 
9
+ module LogWeasel
10
+ class Config
11
+ attr_accessor :key
12
+ end
13
+
14
+ def self.config
15
+ @@config ||= Config.new
16
+ end
17
+
18
+ def self.configure
19
+ yield self.config
20
+
21
+ if defined? ::HoptoadNotifier
22
+ class << ::HoptoadNotifier
23
+ include LogWeasel::HoptoadNotifier;
24
+ end
25
+ end
26
+
27
+ if defined? Resque
28
+ LogWeasel::Resque.initialize!
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ #Rails.application.class.to_s.split("::").first
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'log_weasel/buffered_logger'
3
2
 
4
3
  describe LogWeasel::BufferedLogger do
5
4
  before do
@@ -1,13 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'hoptoad_notifier'
3
- require 'log_weasel/hoptoad_notifier'
4
3
 
5
4
  describe LogWeasel::HoptoadNotifier do
6
5
  before do
7
- class << ::HoptoadNotifier
8
- include LogWeasel::HoptoadNotifier;
9
- end if defined? ::HoptoadNotifier
10
-
6
+ LogWeasel.configure {}
11
7
  HoptoadNotifier.configure {}
12
8
  LogWeasel::Transaction.stubs(:id).returns('123')
13
9
  end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'resque'
3
+ require 'log_weasel'
4
+
5
+ describe LogWeasel do
6
+
7
+ describe ".configure" do
8
+ it "stores key" do
9
+ LogWeasel.configure do |config|
10
+ config.key = "KEY"
11
+ end
12
+ LogWeasel.config.key.should == "KEY"
13
+ end
14
+ end
15
+
16
+ end
@@ -1,11 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'resque'
3
- require 'log_weasel/resque'
4
3
 
5
4
  describe LogWeasel::Resque do
6
5
 
7
6
  before do
8
- LogWeasel::Resque.initialize! :key => 'FOO'
7
+ LogWeasel.configure { |config| config.key = "FOO" }
9
8
  end
10
9
 
11
10
  after do
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
- require 'log_weasel/transaction'
4
+ require 'log_weasel'
5
5
  require 'rspec'
6
6
 
7
7
  require 'active_support/secure_random'
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_weasel
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
4
+ prerelease:
5
+ version: 0.0.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Alon Salant
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-15 00:00:00 -08:00
13
+ date: 2011-02-22 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,8 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
23
  version: "0"
30
24
  type: :development
31
25
  prerelease: false
@@ -37,8 +31,6 @@ dependencies:
37
31
  requirements:
38
32
  - - ">="
39
33
  - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
34
  version: "0"
43
35
  type: :development
44
36
  prerelease: false
@@ -50,9 +42,6 @@ dependencies:
50
42
  requirements:
51
43
  - - ~>
52
44
  - !ruby/object:Gem::Version
53
- segments:
54
- - 1
55
- - 0
56
45
  version: "1.0"
57
46
  type: :development
58
47
  prerelease: false
@@ -64,8 +53,6 @@ dependencies:
64
53
  requirements:
65
54
  - - ">="
66
55
  - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
56
  version: "0"
70
57
  type: :development
71
58
  prerelease: false
@@ -77,9 +64,6 @@ dependencies:
77
64
  requirements:
78
65
  - - ~>
79
66
  - !ruby/object:Gem::Version
80
- segments:
81
- - 3
82
- - 0
83
67
  version: "3.0"
84
68
  type: :runtime
85
69
  prerelease: false
@@ -105,12 +89,14 @@ files:
105
89
  - lib/log_weasel/buffered_logger.rb
106
90
  - lib/log_weasel/hoptoad_notifier.rb
107
91
  - lib/log_weasel/middleware.rb
92
+ - lib/log_weasel/railtie.rb
108
93
  - lib/log_weasel/resque.rb
109
94
  - lib/log_weasel/transaction.rb
110
95
  - lib/log_weasel/version.rb
111
96
  - log_weasel.gemspec
112
97
  - spec/log_weasel/buffered_logger_spec.rb
113
98
  - spec/log_weasel/hoptoad_notifier_spec.rb
99
+ - spec/log_weasel/log_weasel_spec.rb
114
100
  - spec/log_weasel/resque_spec.rb
115
101
  - spec/log_weasel/transaction_spec.rb
116
102
  - spec/spec_helper.rb
@@ -128,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - ">="
130
116
  - !ruby/object:Gem::Version
131
- hash: -994140046389382350
117
+ hash: 2735436436315165741
132
118
  segments:
133
119
  - 0
134
120
  version: "0"
@@ -137,20 +123,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
123
  requirements:
138
124
  - - ">="
139
125
  - !ruby/object:Gem::Version
140
- hash: -994140046389382350
126
+ hash: 2735436436315165741
141
127
  segments:
142
128
  - 0
143
129
  version: "0"
144
130
  requirements: []
145
131
 
146
132
  rubyforge_project: log_weasel
147
- rubygems_version: 1.3.7
133
+ rubygems_version: 1.5.2
148
134
  signing_key:
149
135
  specification_version: 3
150
- summary: log_weasel-0.0.5
136
+ summary: log_weasel-0.0.6
151
137
  test_files:
152
138
  - spec/log_weasel/buffered_logger_spec.rb
153
139
  - spec/log_weasel/hoptoad_notifier_spec.rb
140
+ - spec/log_weasel/log_weasel_spec.rb
154
141
  - spec/log_weasel/resque_spec.rb
155
142
  - spec/log_weasel/transaction_spec.rb
156
143
  - spec/spec_helper.rb