scribbler 0.1.1 → 0.1.2
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.markdown → README.md} +34 -3
- data/lib/scribbler/base.rb +19 -8
- data/lib/scribbler/configurator.rb +5 -1
- data/lib/scribbler/version.rb +1 -1
- data/spec/scribbler/base_spec.rb +14 -16
- data/spec/scribbler/configurator_spec.rb +2 -3
- data/spec/spec_helper.rb +1 -3
- metadata +5 -5
@@ -23,14 +23,28 @@ to your Gemfile and
|
|
23
23
|
|
24
24
|
Then
|
25
25
|
|
26
|
-
|
26
|
+
scribbler install # For options do `scribbler` first
|
27
27
|
|
28
28
|
You'll find your configuration options in `config/initializers/scribbler.rb`.
|
29
|
+
**Better, more documented examples in the template file provided by `scribbler install`**
|
29
30
|
As an example, with this configuration file in a Rails app called `Blogger`:
|
30
31
|
|
31
32
|
Scribbler::Base.configure do
|
32
33
|
config.application_include = true
|
34
|
+
|
35
|
+
# config.log_directory = File.new '/a/better/path'
|
36
|
+
|
33
37
|
config.logs = %w[production delayed_job]
|
38
|
+
|
39
|
+
config.use_template_by_default = true # Default: false
|
40
|
+
|
41
|
+
# config.template = proc do |options|
|
42
|
+
# <<-MSG
|
43
|
+
# ##########
|
44
|
+
# Cool template bro!
|
45
|
+
# Message: #{options[:message]}
|
46
|
+
# MSG
|
47
|
+
# end
|
34
48
|
end
|
35
49
|
|
36
50
|
You are given a few methods for free. To get the production logfile location:
|
@@ -62,8 +76,25 @@ More importantly you're given access to a sweet `log` method:
|
|
62
76
|
Blogger.log File.expand_path(File.join(File.dirname(__FILE__), 'logfile.log')), :message => "#{e} broke stuff"
|
63
77
|
Scribbler::Base.log File.expand_path(File.join(File.dirname(__FILE__), 'logfile.log')), :message => "#{e} broke stuff"
|
64
78
|
|
79
|
+
Log options with the default template proc:
|
80
|
+
|
81
|
+
options - Hash of options for logging on Ngin
|
82
|
+
:error - Error object, mostly for passing to NewRelic
|
83
|
+
:message - Message to log in the actual file [REQUIRED]
|
84
|
+
:custom_fields - Custom fields dropped into the default template
|
85
|
+
:template - Whether or not to use the template at this log
|
86
|
+
:new_relic - Notify NewRelic of the error (default: true)
|
87
|
+
|
88
|
+
With the template enabled (either during call to log [:template => true] or by setting to
|
89
|
+
be used by default) you will have each log entry wrapped into a template to pretty-up and
|
90
|
+
get some more boilerplate data. As you can see in the config above. See method
|
91
|
+
docs and specs for more information.
|
92
|
+
|
65
93
|
## Todo
|
66
94
|
|
67
|
-
*
|
68
|
-
*
|
95
|
+
* Configure the module/class receiving the include
|
96
|
+
* Configurable notification gem (NewRelic, Airbrake, etc.)
|
69
97
|
* Currently attempts to notify NewRelic if its there, abstract and allow custom services
|
98
|
+
* Allow a class to set default options for a log call within itself
|
99
|
+
* Allow there to be a log made without the option[:message], in case its all custom_fields or someting
|
100
|
+
* Allow event hooks on log call?
|
data/lib/scribbler/base.rb
CHANGED
@@ -102,7 +102,8 @@ module Scribbler
|
|
102
102
|
# Returns Nothing.
|
103
103
|
def self.log(location, options={})
|
104
104
|
options = {
|
105
|
-
:template => config.use_template_by_default
|
105
|
+
:template => config.use_template_by_default,
|
106
|
+
:stack_frame => options[:call_stack] ? Kernel.caller[1..-1] : nil
|
106
107
|
}.merge options
|
107
108
|
begin
|
108
109
|
NewRelic::Agent.notice_error(options[:error]) if options[:error] and options[:new_relic] != false
|
@@ -160,13 +161,21 @@ module Scribbler
|
|
160
161
|
#
|
161
162
|
# Returns Nothing
|
162
163
|
def self.apply_to_log(location, options={})
|
163
|
-
if
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
if can_apply_to_log? location, options
|
165
|
+
File.open(find_file_at(location), 'a') do |f|
|
166
|
+
f.puts build_with_template(options)
|
167
|
+
end
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|
171
|
+
# TODO: Fix to work with any template
|
172
|
+
def self.can_apply_to_log?(location, options)
|
173
|
+
location.present? and
|
174
|
+
(options[:message].present? or
|
175
|
+
options[:object].present? or
|
176
|
+
options[:custom_fields].present?)
|
177
|
+
end
|
178
|
+
|
170
179
|
# Attempts to turn a symbol or string into the *_log_location method that
|
171
180
|
# was auto-build based on Configurator.logs and finds the file path
|
172
181
|
#
|
@@ -182,12 +191,14 @@ module Scribbler
|
|
182
191
|
# # => :another_file # The method `another_file_log_location` does not exist
|
183
192
|
#
|
184
193
|
# Returns Nothing
|
185
|
-
#
|
186
|
-
# TODO: allow the log base directory to be set in configurator
|
187
194
|
def self.find_file_at(location)
|
188
195
|
if location.is_a?(Symbol) or location.is_a?(String)
|
189
196
|
real_method = location.to_s + "_log_location"
|
190
|
-
|
197
|
+
if respond_to?(real_method)
|
198
|
+
location = send(real_method)
|
199
|
+
else
|
200
|
+
location = "#{config.log_directory.to_s}/#{location.to_s}"
|
201
|
+
end
|
191
202
|
end
|
192
203
|
location
|
193
204
|
end
|
@@ -135,7 +135,11 @@ module Scribbler
|
|
135
135
|
template << "#{Time.now}\n"
|
136
136
|
template << "#{options[:object].class.name}: #{if_id}\n" if options[:object]
|
137
137
|
template << "#{custom_fields}\n" if custom_fields.present?
|
138
|
-
template << "#{options[:message]}\n
|
138
|
+
template << "#{options[:message]}\n"
|
139
|
+
template << "Call Stack:\n#{options[:stack_frame].join("\n")}" if options[:call_stack]
|
140
|
+
template << "\n"
|
141
|
+
|
142
|
+
template
|
139
143
|
end
|
140
144
|
end
|
141
145
|
end
|
data/lib/scribbler/version.rb
CHANGED
data/spec/scribbler/base_spec.rb
CHANGED
@@ -58,17 +58,17 @@ module Scribbler
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "calls log, skips templater and still works" do
|
61
|
-
|
61
|
+
subject.send(:build_with_template,
|
62
62
|
:object => some_object,
|
63
63
|
:template => false,
|
64
64
|
:message => "test\n123").should == "test\n123"
|
65
65
|
end
|
66
66
|
|
67
67
|
it "calls log and gets message with template wrapper" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
subject.send(:build_with_template,
|
69
|
+
:template => true,
|
70
|
+
:object => some_object,
|
71
|
+
:message => <<-MSG
|
72
72
|
test
|
73
73
|
123
|
74
74
|
MSG
|
@@ -83,11 +83,11 @@ module Scribbler
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "calls log and gets message with custom params" do
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
subject.send(:build_with_template,
|
87
|
+
:template => true,
|
88
|
+
:object => some_object,
|
89
|
+
:custom_fields => {:test1 => 1, :test2 => 2},
|
90
|
+
:message => <<-MSG
|
91
91
|
test
|
92
92
|
123
|
93
93
|
MSG
|
@@ -122,12 +122,10 @@ module Scribbler
|
|
122
122
|
|
123
123
|
it "should build a template and try to put it in a file" do
|
124
124
|
options = { :message => "..." }
|
125
|
-
|
125
|
+
file = mock(:puts => true)
|
126
126
|
subject.should_receive(:build_with_template).with options
|
127
|
-
|
128
|
-
|
129
|
-
file_stub.should_receive :close
|
130
|
-
File.should_receive(:open) { file_stub }
|
127
|
+
subject.should_receive(:send).with "test_log_log_location"
|
128
|
+
File.should_receive(:open).and_yield(file)
|
131
129
|
subject.apply_to_log :test_log, options
|
132
130
|
end
|
133
131
|
end
|
@@ -137,7 +135,7 @@ module Scribbler
|
|
137
135
|
# in case we have bad config data lingering
|
138
136
|
subject.stub(:respond_to?).with('test_log_log_location').and_return false
|
139
137
|
subject.should_not_receive(:test_log_log_location)
|
140
|
-
subject.find_file_at(:test_log).should ==
|
138
|
+
subject.find_file_at(:test_log).should == "#{Dir.pwd}/log/test_log"
|
141
139
|
end
|
142
140
|
|
143
141
|
it "finds a file method defined" do
|
@@ -31,10 +31,9 @@ module Scribbler
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "falls back to pwd/log without rails" do
|
34
|
-
|
34
|
+
subject.log_directory = nil #RESET
|
35
35
|
Rails.should_receive(:root).and_raise(NameError)
|
36
|
-
Dir.
|
37
|
-
subject.log_directory.should == 'dir/log'
|
36
|
+
subject.log_directory.should == "#{Dir.pwd}/log"
|
38
37
|
end
|
39
38
|
|
40
39
|
it "sets the log directory" do
|
data/spec/spec_helper.rb
CHANGED
@@ -18,9 +18,7 @@ RSpec.configure do |config|
|
|
18
18
|
config.filter_run :focus
|
19
19
|
config.color = true
|
20
20
|
config.after(:all) do # Force a reset of some Classes
|
21
|
-
project_dir =
|
22
|
-
project_dir.delete_at(-1)
|
23
|
-
project_dir = project_dir.join('/')
|
21
|
+
project_dir = File.expand_path('../..', __FILE__)
|
24
22
|
singletons.each do |s|
|
25
23
|
Scribbler.send(:remove_const, s)
|
26
24
|
load "#{project_dir}/lib/scribbler/#{s.downcase}.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scribbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2012-
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -104,7 +104,7 @@ files:
|
|
104
104
|
- .travis.yml
|
105
105
|
- Gemfile
|
106
106
|
- Gemfile.lock
|
107
|
-
- README.
|
107
|
+
- README.md
|
108
108
|
- Rakefile
|
109
109
|
- bin/scribbler
|
110
110
|
- lib/scribbler.rb
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash:
|
143
|
+
hash: 1839906776393005062
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
segments:
|
151
151
|
- 0
|
152
|
-
hash:
|
152
|
+
hash: 1839906776393005062
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
155
|
rubygems_version: 1.8.24
|