resque-logger 0.1.0 → 0.2.0
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/README.md +2 -1
- data/lib/resque/plugins/logger.rb +9 -3
- data/lib/resque_logger.rb +4 -4
- data/lib/resque_logger/version.rb +1 -1
- data/spec/lib/resque/plugins/logger_spec.rb +92 -7
- data/spec/lib/resque_logger_spec.rb +8 -3
- metadata +4 -14
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Configuration
|
|
20
20
|
formatter: Logger::Formatter.new, # optional
|
21
21
|
}
|
22
22
|
|
23
|
-
Resque.
|
23
|
+
Resque.logger_config = config
|
24
24
|
|
25
25
|
Usage
|
26
26
|
=====
|
@@ -32,6 +32,7 @@ Usage
|
|
32
32
|
extend Resque::Plugins::Logger
|
33
33
|
|
34
34
|
@queue = :my_killer_worker_job
|
35
|
+
@log_name = "my_killer_log_name.log" # Optional - defaults to using the queue name.
|
35
36
|
|
36
37
|
def self.perform(args = {})
|
37
38
|
(...)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module Resque
|
4
4
|
module Plugins
|
5
5
|
module Logger
|
6
|
+
DEFAULT_LOG_NAME = "worker.log"
|
6
7
|
#
|
7
8
|
# Returns a logger instance based on queue name.
|
8
9
|
#
|
@@ -11,18 +12,23 @@ module Resque
|
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
|
-
|
15
15
|
#
|
16
16
|
# Creates a new instance of logger given a queue name, retrieving
|
17
17
|
# configuration from Resque.logger.
|
18
18
|
#
|
19
19
|
def create_logger
|
20
|
-
config = Resque.
|
20
|
+
config = Resque.logger_config
|
21
21
|
log_path = config[:folder]
|
22
22
|
class_name = config[:class_name]
|
23
23
|
class_args = config[:class_args]
|
24
24
|
|
25
|
-
|
25
|
+
file_basename = @log_name ||
|
26
|
+
(if (queue_name = Resque.queue_from_class(self))
|
27
|
+
"#{queue_name}.log"
|
28
|
+
else
|
29
|
+
DEFAULT_LOG_NAME
|
30
|
+
end)
|
31
|
+
file_path = File.join log_path, file_basename
|
26
32
|
|
27
33
|
logger = class_name.new file_path, *class_args
|
28
34
|
logger.level = config[:level] if config[:level]
|
data/lib/resque_logger.rb
CHANGED
@@ -5,8 +5,8 @@ require "resque/setup"
|
|
5
5
|
|
6
6
|
module ResqueLogger
|
7
7
|
module ClassMethods
|
8
|
-
def
|
9
|
-
@
|
8
|
+
def logger_config
|
9
|
+
@logger_config
|
10
10
|
end
|
11
11
|
|
12
12
|
#
|
@@ -21,10 +21,10 @@ module ResqueLogger
|
|
21
21
|
#
|
22
22
|
# Hash keys will be symbols to work.
|
23
23
|
#
|
24
|
-
def
|
24
|
+
def logger_config=(options)
|
25
25
|
check_logger_args! options
|
26
26
|
|
27
|
-
@
|
27
|
+
@logger_config = options
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -3,15 +3,17 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Resque::Plugins::Logger do
|
6
|
-
|
6
|
+
before do
|
7
|
+
@worker_queue = :worker_queue
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
class ResqueWorker
|
10
|
+
extend Resque::Plugins::Logger
|
10
11
|
|
11
|
-
|
12
|
+
@queue = @worker_queue
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def self.perform(args = {})
|
15
|
+
logger.info 'It works!'
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -29,11 +31,12 @@ describe Resque::Plugins::Logger do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
before :each do
|
32
|
-
Resque.stub(:
|
34
|
+
Resque.stub(:logger_config).and_return(config)
|
33
35
|
logger_mock.should_receive(:info).any_number_of_times
|
34
36
|
|
35
37
|
# FIXME: find a better way to test
|
36
38
|
ResqueWorker.instance_variable_set '@logger', nil
|
39
|
+
ResqueWorker.instance_variable_set(:@queue, @worker_queue)
|
37
40
|
end
|
38
41
|
|
39
42
|
describe 'getting a logger based on queue' do
|
@@ -65,6 +68,88 @@ describe Resque::Plugins::Logger do
|
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
71
|
+
describe 'log file auto-naming' do
|
72
|
+
before(:each) do
|
73
|
+
config.delete :class_args
|
74
|
+
config.delete :level
|
75
|
+
config.delete :formatter
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'class instance variable is set' do
|
79
|
+
before(:each) do
|
80
|
+
ResqueWorker.instance_variable_set(:@queue, "custom_queue")
|
81
|
+
@file_path = File.join config[:folder], "custom_queue.log"
|
82
|
+
end
|
83
|
+
after(:each) do
|
84
|
+
ResqueWorker.instance_variable_set(:@queue, @worker_queue)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'uses the correct log name' do
|
88
|
+
Logger.should_receive(:new).with(@file_path).and_return(logger_mock)
|
89
|
+
|
90
|
+
ResqueWorker.perform
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'class queue method exists' do
|
95
|
+
before(:each) do
|
96
|
+
ResqueWorker.instance_variable_set(:@queue, nil)
|
97
|
+
ResqueWorker.class_eval do
|
98
|
+
def self.queue
|
99
|
+
"another_queue"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@file_path = File.join config[:folder], "another_queue.log"
|
103
|
+
end
|
104
|
+
after(:each) do
|
105
|
+
ResqueWorker.class_eval do
|
106
|
+
class << self
|
107
|
+
remove_method :queue
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'uses the correct log name' do
|
113
|
+
Logger.should_receive(:new).with(@file_path).and_return(logger_mock)
|
114
|
+
|
115
|
+
ResqueWorker.perform
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'no queue name is specified' do
|
120
|
+
before do
|
121
|
+
ResqueWorker.instance_variable_set(:@queue, nil)
|
122
|
+
Resque.queue_from_class(ResqueWorker).should be_false
|
123
|
+
end
|
124
|
+
it 'uses a default log name' do
|
125
|
+
default_file_path = File.join(config[:folder], Resque::Plugins::Logger::DEFAULT_LOG_NAME)
|
126
|
+
Logger.should_receive(:new).with(default_file_path).and_return(logger_mock)
|
127
|
+
|
128
|
+
ResqueWorker.perform
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'explicitly setting the log name' do
|
134
|
+
before(:each) do
|
135
|
+
@base = "hey_a_log_file.log"
|
136
|
+
@file_path = File.join config[:folder], @base
|
137
|
+
ResqueWorker.instance_variable_set("@log_name", @base)
|
138
|
+
config.delete :level
|
139
|
+
config.delete :formatter
|
140
|
+
end
|
141
|
+
after(:each) do
|
142
|
+
ResqueWorker.instance_variable_set("@log_name", nil)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'uses the log_name method' do
|
146
|
+
config.delete :class_args
|
147
|
+
Logger.should_receive(:new).with(@file_path).and_return(logger_mock)
|
148
|
+
|
149
|
+
ResqueWorker.perform
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
68
153
|
describe 'setting logger options from configuration' do
|
69
154
|
before :each do
|
70
155
|
Logger.stub(:new).and_return(logger_mock)
|
@@ -11,7 +11,7 @@ describe ResqueLogger do
|
|
11
11
|
|
12
12
|
error = ArgumentError.new 'Folder must be supplied'
|
13
13
|
|
14
|
-
expect { Resque.
|
14
|
+
expect { Resque.logger_config = config }.to raise_error(error.class, error.message)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises an error if class name is not found' do
|
@@ -19,11 +19,16 @@ describe ResqueLogger do
|
|
19
19
|
|
20
20
|
error = ArgumentError.new 'Logger must be supplied'
|
21
21
|
|
22
|
-
expect { Resque.
|
22
|
+
expect { Resque.logger_config = config }.to raise_error(error.class, error.message)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'not raises otherwise' do
|
26
|
-
expect { Resque.
|
26
|
+
expect { Resque.logger_config = config }.to_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'does not collide with the Resque.logger namespace' do
|
30
|
+
Resque.logger_config = config
|
31
|
+
expect { Resque.logger.info("Test message") }.to_not raise_error
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -95,26 +95,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
- - ! '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
hash: 1231085515247237098
|
101
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
99
|
none: false
|
103
100
|
requirements:
|
104
101
|
- - ! '>='
|
105
102
|
- !ruby/object:Gem::Version
|
106
103
|
version: '0'
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
hash: 1231085515247237098
|
110
104
|
requirements: []
|
111
105
|
rubyforge_project: resque-logger
|
112
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.23
|
113
107
|
signing_key:
|
114
108
|
specification_version: 3
|
115
109
|
summary: A Resque plugin to provides logger for each worker
|
116
|
-
test_files:
|
117
|
-
- spec/lib/resque/plugins/logger_spec.rb
|
118
|
-
- spec/lib/resque_logger_spec.rb
|
119
|
-
- spec/spec_helper.rb
|
120
|
-
- spec/support/rspec_macros.rb
|
110
|
+
test_files: []
|