debug_me 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -8
- data/lib/debug_me.rb +8 -1
- data/lib/debug_me/version.rb +1 -1
- data/tests/debug_me_test.rb +43 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b12a0c426af49f51958f84424b8bd2160f1b3a139d75b7c83a8b7021adb8788d
|
4
|
+
data.tar.gz: 4c7b31bbddfa1a029410413c3847ec31ac678fe004a0e53d263457f4c822c1de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac86537e986b53194dce7d08605aaef788d5a48849f205e80b82ca27cb6af01793952b93b305dad2e0a8ea7f37b75d153de2cba7630d0d41ce6424e1e9d08133
|
7
|
+
data.tar.gz: 3dbcce464705ce68215d50e9e28b6c56a38e94b869edb7340b7ce648c3acced7db2ccf40b50ad83df8d75812e0c6d046725cdecd0537f8e64ad78651c4e6047e
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
A tool to print the labeled value of variables.
|
4
4
|
|
5
|
-
This thing is pretty old;but, so am I.
|
6
|
-
in our hair we still
|
5
|
+
This thing is pretty old; but, so am I. Even with the gray
|
6
|
+
in our hair we still do the job.
|
7
7
|
|
8
|
-
There are much complex/comprehensive
|
8
|
+
There are much more complex/comprehensive
|
9
9
|
ways of debugging in a complex application. But,
|
10
10
|
you know, I keep returning to this little method
|
11
11
|
time after time. I guess that marks me as a geezer.
|
@@ -15,7 +15,8 @@ DebugMe::debug_me(){} works with local, instance and class variables.
|
|
15
15
|
|
16
16
|
## Recent Changes
|
17
17
|
|
18
|
-
* 1.0.
|
18
|
+
* 1.0.5 Added support for an instance of a Logger class.
|
19
|
+
* 1.0.4 Added :strftime to the options; changed the default format from decimal seconds since epic to something that is more easy comprehend on a clock.
|
19
20
|
|
20
21
|
## Installation
|
21
22
|
|
@@ -94,7 +95,7 @@ The default options is a global constant `DebugMeDefaultOptions` that is outside
|
|
94
95
|
|
95
96
|
Notice that this constant is outside of the DebugMe's module namespace.
|
96
97
|
|
97
|
-
```
|
98
|
+
```ruby
|
98
99
|
DebugMeDefaultOptions = {
|
99
100
|
tag: 'DEBUG', # A tag to prepend to each output line
|
100
101
|
time: true, # Include a time-stamp in front of the tag
|
@@ -104,23 +105,88 @@ DebugMeDefaultOptions = {
|
|
104
105
|
ivar: true, # Include instance variables in the output
|
105
106
|
cvar: true, # Include class variables in the output
|
106
107
|
cconst: true, # Include class constants
|
108
|
+
logger: nil, # Pass in a logger class instance like Rails.logger
|
107
109
|
file: $stdout # The output file
|
108
110
|
}
|
109
111
|
```
|
110
112
|
|
111
113
|
If you want the output of the method to always go to STDERR then do this:
|
112
114
|
|
113
|
-
```
|
115
|
+
```ruby
|
114
116
|
require 'debug_me'
|
115
|
-
DebugMeDefaultOptions[:file] = $stderr
|
117
|
+
DebugMeDefaultOptions[:file] = $stderr # or STDERR
|
116
118
|
```
|
117
119
|
If you want the `debug_me` output to go to a real file:
|
118
120
|
|
119
|
-
```
|
121
|
+
```ruby
|
120
122
|
DebugMeDefaultOptions[:file] = File.open('debug_me.log', 'w')
|
121
123
|
|
122
124
|
```
|
123
125
|
|
126
|
+
## Using a Logger class instance
|
127
|
+
|
128
|
+
If you are working in Rails and want all the `debug_me` output to go to the Rails.logger its as easy as:
|
129
|
+
```ruby
|
130
|
+
DebugMeDefaultOptions[:logger] = Rails.logger
|
131
|
+
|
132
|
+
```
|
133
|
+
|
134
|
+
Or while working in rails you only want to add a marker to the Rails.logger do this:
|
135
|
+
```ruby
|
136
|
+
debug_me(logger: Rails.logger, tag: 'Hello World')
|
137
|
+
```
|
138
|
+
|
139
|
+
If you are working in Rails and want to use both the standard `debug_me` functions and occassionally put stuff into the Rails.logger but do not want to always remember the option settings then do something line this in a `config/initializers/aaaaa_debug_me.rb` file:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# config/initializers/aaaaa_debug_me.rb
|
143
|
+
|
144
|
+
require 'debug_me'
|
145
|
+
|
146
|
+
module DebugMe
|
147
|
+
def log_me(message, options={}, &block)
|
148
|
+
options = {logger: Rails.logger, time: false, header: false, tag: message}
|
149
|
+
block_given? ? debug_me(options, block) : debug_me(options)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
include DebugMe
|
154
|
+
|
155
|
+
# Just setup the base name. The parent path will be added below ...
|
156
|
+
debug_me_file_name = 'debug_me'
|
157
|
+
|
158
|
+
# NOTE: you could add a timestamp to the filename
|
159
|
+
# debug_me_file_name += '_' + Time.now.strftime('%Y%m%d%H%M%S')
|
160
|
+
|
161
|
+
debug_me_file_name += '_' + Process.argv0.gsub('/',' ').split(' ').last
|
162
|
+
# NOTE: by using the Process.argv0 ... you get multiple log files for
|
163
|
+
# rails, rake, sidekiq etc.
|
164
|
+
|
165
|
+
debug_me_file_name += '.log'
|
166
|
+
|
167
|
+
debug_me_filepath = Rails.root + 'log' + debug_me_file_name
|
168
|
+
|
169
|
+
debug_me_file = File.open(debug_me_filepath, 'w')
|
170
|
+
|
171
|
+
debug_me_file.puts <<~RULER
|
172
|
+
|
173
|
+
==================== Starting New Test Run --------->>>>>>
|
174
|
+
|
175
|
+
RULER
|
176
|
+
|
177
|
+
# Set application wide options in the DebugMeDefaultOptions hash
|
178
|
+
DebugMeDefaultOptions[:file] = debug_me_file
|
179
|
+
|
180
|
+
debug_me{['ENV']}
|
181
|
+
|
182
|
+
```
|
183
|
+
|
184
|
+
What that does for your Rails application is dump all of your system environment variables and their values to a debug_me log file in the log directory of the application.
|
185
|
+
|
186
|
+
It also adds a new method `log_me` which you can use to send stuff to the `Rails.logger` instance. The method used by `debug_me` for the `logger` instance is always the `debug` method.
|
187
|
+
|
188
|
+
## Conclusion
|
189
|
+
|
124
190
|
The rest of the default options are obvious.
|
125
191
|
|
126
192
|
You can always over-ride the default options on a case by case basis like this:
|
data/lib/debug_me.rb
CHANGED
@@ -10,6 +10,8 @@ DebugMeDefaultOptions = {
|
|
10
10
|
ivar: true, # Include instance variables in the output
|
11
11
|
cvar: true, # Include class variables in the output
|
12
12
|
cconst: true, # Include class constants
|
13
|
+
logger: nil, # Pass in an instance of logger class like Rails.logger
|
14
|
+
# must respond_to? :debug
|
13
15
|
file: $stdout # The output file
|
14
16
|
}
|
15
17
|
|
@@ -25,6 +27,7 @@ module DebugMe
|
|
25
27
|
out_string = ''
|
26
28
|
|
27
29
|
f = options[:file]
|
30
|
+
l = options[:logger]
|
28
31
|
s = ''
|
29
32
|
s += Time.now.strftime(options[:strftime])+' ' if options[:time]
|
30
33
|
s += "#{options[:tag]}"
|
@@ -60,10 +63,14 @@ module DebugMe
|
|
60
63
|
f.flush
|
61
64
|
end
|
62
65
|
|
66
|
+
unless l.nil?
|
67
|
+
l.debug(out_string) if l.respond_to? :debug
|
68
|
+
end
|
69
|
+
|
63
70
|
return out_string
|
64
71
|
end ## def debug_me( options={}, &block )
|
65
72
|
|
66
73
|
# def log_me(msg, opts={})
|
67
|
-
# debug_me({:
|
74
|
+
# debug_me({tag: msg, header: false}.merge(opts))
|
68
75
|
# end
|
69
76
|
end # module DebugMe
|
data/lib/debug_me/version.rb
CHANGED
data/tests/debug_me_test.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'awesome_print'
|
4
|
+
require 'logger'
|
5
|
+
require 'pathname'
|
6
|
+
|
3
7
|
require_relative '../lib/debug_me'
|
4
8
|
include DebugMe
|
5
9
|
|
@@ -224,6 +228,45 @@ describe DebugMe do
|
|
224
228
|
|
225
229
|
end # describe "works with class CONSTANTS" do
|
226
230
|
|
231
|
+
describe "works with a Logger class" do
|
232
|
+
|
233
|
+
it 'default logger class is nil' do
|
234
|
+
DebugMeDefaultOptions[:logger].must_equal nil
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'works with standard ruby Logger class' do
|
238
|
+
logger_output_path = Pathname.pwd + 'logger_class_output.txt'
|
239
|
+
logger_output_path.exist?.must_equal false
|
240
|
+
|
241
|
+
logger = Logger.new(logger_output_path)
|
242
|
+
logger.level = Logger::DEBUG
|
243
|
+
|
244
|
+
out_string = debug_me(
|
245
|
+
logger: logger, # Use instance of Ruby's Logger
|
246
|
+
time: false, # turn off debug_me's timestamp
|
247
|
+
file: nil, # don't write to STDOUT the default
|
248
|
+
tag: 'Hello World' # say hello
|
249
|
+
)
|
250
|
+
# Generates an entry like this:
|
251
|
+
=begin
|
252
|
+
# Logfile created on 2020-04-27 16:16:38 -0500 by logger.rb/v1.4.2
|
253
|
+
D, [2020-04-27T16:16:38.580889 #54662] DEBUG -- : Hello World Source: debug_me_test.rb:244:in `block (3 levels) in <main>'
|
254
|
+
=end
|
255
|
+
|
256
|
+
lines = logger_output_path.read.split("\n")
|
257
|
+
|
258
|
+
lines.size.must_equal 2
|
259
|
+
|
260
|
+
lines[0].start_with?('# Logfile created on').must_equal true
|
261
|
+
lines[1].start_with?('D, [').must_equal true
|
262
|
+
lines[1].include?('DEBUG').must_equal true
|
263
|
+
lines[1].include?('Hello World').must_equal true
|
264
|
+
lines[1].include?('debug_me_test.rb').must_equal true
|
265
|
+
lines[1].include?(out_string.chomp).must_equal true
|
266
|
+
|
267
|
+
logger_output_path.delete
|
268
|
+
end
|
227
269
|
|
270
|
+
end
|
228
271
|
|
229
272
|
end # describe DebugMe do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.1.2
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A tool to print the labeled value of variables.
|