warning-shot 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/warning_shot.rb +0 -8
- data/lib/warning_shot/config_parser.rb +5 -5
- data/lib/warning_shot/dep_checker.rb +149 -185
- data/lib/warning_shot/logger.rb +90 -7
- data/lib/warning_shot/version.rb +1 -1
- data/website/index.html +1 -1
- metadata +1 -1
data/History.txt
CHANGED
data/lib/warning_shot.rb
CHANGED
@@ -6,8 +6,6 @@ require 'net/http'
|
|
6
6
|
require 'net/https'
|
7
7
|
require 'uri'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
9
|
#IMPORTANT remember to add new includes to Manifest.txt
|
12
10
|
Dir.glob(File.join(File.dirname(__FILE__), "warning_shot/*.rb")).each {|f|
|
13
11
|
require f
|
@@ -18,7 +16,6 @@ include RippleNetworks::WarningShot
|
|
18
16
|
=begin
|
19
17
|
Useful URLS:
|
20
18
|
http://rubygems.rubyforge.org/rdoc/
|
21
|
-
http://en.wikipedia.org/wiki/ANSI_escape_code
|
22
19
|
http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
|
23
20
|
=end
|
24
21
|
|
@@ -27,11 +24,6 @@ include RippleNetworks::WarningShot
|
|
27
24
|
TODOs
|
28
25
|
-->Change from http reqs to protocol http://etc, memcached://etc, ftp://etc...
|
29
26
|
|
30
|
-
-->flag to install gems in first alt gem path
|
31
|
-
|
32
|
-
-->Implement a WarningShot.logger.(info,fatal,etc...) instead of current logging mechanism
|
33
|
-
====>In programatic interface take a logger and override (for passing in external loggers)
|
34
|
-
|
35
27
|
-->Further de-couple the dep_checker class
|
36
28
|
|
37
29
|
-->Update GemHandler#installed? to use Gem::Requirement#satisfied_by?
|
@@ -24,20 +24,20 @@ module RippleNetworks
|
|
24
24
|
ws.configs[config_file] = global.concat(running_env)
|
25
25
|
ws.configs[config_file].uniq!
|
26
26
|
|
27
|
-
ws.
|
27
|
+
ws.logger.notice("LOADED: #{config_file}.yml")
|
28
28
|
rescue Errno::ENOENT => e
|
29
29
|
ws.configs[config_file] = {}
|
30
30
|
configs_not_found += 1
|
31
|
-
ws.
|
31
|
+
ws.logger.warning("NOT FOUND: #{config_file}.yml")
|
32
32
|
rescue Exception => e
|
33
|
-
ws.
|
33
|
+
ws.logger.error(e.inspect)
|
34
34
|
ws.configs[config_file] = {}
|
35
|
-
ws.
|
35
|
+
ws.logger.error("MALFORMED: #{config_file}.yml")
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
if configs_not_found == DepChecker::DEP_FILES.size
|
40
|
-
ws.
|
40
|
+
ws.logger.info("No configuration files found!\n\t\tTo generate run 'warning-shot --templates=PATH'")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -19,7 +19,7 @@ module RippleNetworks
|
|
19
19
|
=end
|
20
20
|
class DepChecker
|
21
21
|
include RippleNetworks::WarningShot
|
22
|
-
attr_reader :options, :warnings, :errors, :configs
|
22
|
+
attr_reader :options, :warnings, :errors, :configs, :logger
|
23
23
|
|
24
24
|
LIB_DIRECTORY = $:[0]
|
25
25
|
|
@@ -52,33 +52,22 @@ module RippleNetworks
|
|
52
52
|
:templates => false,
|
53
53
|
:gempath => nil
|
54
54
|
}
|
55
|
-
|
56
|
-
#Set up CLEAR and Windows Add'l requirement
|
57
|
-
if PLATFORM =~ /win32/
|
58
|
-
CLEAR = `cls`
|
59
|
-
begin
|
60
|
-
require 'Win32/Console/ANSI'
|
61
|
-
rescue LoadError => e
|
62
|
-
puts "Run: 'gem install win32console' for colored output"
|
63
|
-
end
|
64
|
-
else
|
65
|
-
CLEAR = `clear`
|
66
|
-
end
|
67
55
|
|
68
56
|
|
69
57
|
def initialize(options=DEFAULTS)
|
70
58
|
@original_requires = $".clone
|
71
59
|
|
72
|
-
ObjectSpace.define_finalizer(self, lambda{ @log_file.close unless @log_file.closed? })
|
73
|
-
|
74
60
|
#Add directory information to defaults
|
75
|
-
DEFAULTS[:log] = File.join(options[:dir],"log","warning_shot_#{options[:environment]}.log")
|
76
61
|
DEFAULTS[:configs] = File.join(options[:dir],"config","warning_shot")
|
77
|
-
|
78
62
|
@options = DEFAULTS.merge(options)
|
79
63
|
|
80
64
|
#Map to correct running environment
|
81
65
|
@options[:environment] = ENVIRONMENT_MAP[@options[:environment]]
|
66
|
+
|
67
|
+
@logger = Logger.new(
|
68
|
+
(@options[:log] || File.join(@options[:dir],"log","warning_shot_#{@options[:environment]}.log")),
|
69
|
+
{:verbose => @options[:verbose], :flush => @options[:flush]}
|
70
|
+
)
|
82
71
|
|
83
72
|
#No errors or warnings
|
84
73
|
@errors = 0
|
@@ -86,16 +75,9 @@ module RippleNetworks
|
|
86
75
|
|
87
76
|
#initalize config file hash
|
88
77
|
@configs = {}
|
89
|
-
|
90
|
-
#Flush log
|
91
|
-
flush_log! if @options[:flush]
|
92
|
-
|
93
|
-
#Open log
|
94
|
-
@log_file = File.open(@options[:log],"a+")
|
95
78
|
|
96
79
|
#Check dependencies
|
97
80
|
@which_installed = has_binary_prereqs?
|
98
|
-
puts CLEAR if @options[:verbose]
|
99
81
|
end
|
100
82
|
|
101
83
|
=begin rdoc
|
@@ -149,68 +131,117 @@ module RippleNetworks
|
|
149
131
|
=end
|
150
132
|
def run
|
151
133
|
start_time = Time.now
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
record("Framework: #{@framework}")
|
157
|
-
|
158
|
-
section("Loading YAML files:")
|
159
|
-
ConfigParser.run(self)
|
160
|
-
|
161
|
-
section("Preloading classes")
|
162
|
-
class_loader("preload")
|
163
|
-
|
164
|
-
section("Checking class dependencies")
|
165
|
-
count = class_loader("classes")
|
166
|
-
record "#{count} classes not found",:error if count > 0
|
134
|
+
tmp_errors = 0
|
135
|
+
|
136
|
+
@logger.heading
|
137
|
+
@logger.heading "WarningShot (v. #{VERSION::INTERNAL}) - started @ #{start_time}"
|
167
138
|
|
168
|
-
|
169
|
-
|
170
|
-
|
139
|
+
check_framework
|
140
|
+
@logger.info("Environment: #{@options[:environment]}")
|
141
|
+
@logger.info("Framework: #{@framework}")
|
171
142
|
|
172
|
-
|
173
|
-
|
174
|
-
record "#{count} files/directories not found", :error if count > 0
|
143
|
+
@logger.heading("Loading YAML files:")
|
144
|
+
ConfigParser.run(self)
|
175
145
|
|
176
|
-
|
177
|
-
|
178
|
-
record "#{count} sites unavailable", :error if count > 0
|
146
|
+
@logger.heading("Preloading classes")
|
147
|
+
class_loader("preload")
|
179
148
|
|
180
|
-
|
181
|
-
|
149
|
+
@logger.heading("Checking class dependencies")
|
150
|
+
tmp_errors = class_loader("classes")
|
151
|
+
if tmp_errors > 0
|
152
|
+
@errors += tmp_errors
|
153
|
+
@logger.error("#{tmp_errors} classes not found!")
|
154
|
+
else
|
155
|
+
@logger.notice("All class dependencies found.")
|
156
|
+
end
|
157
|
+
|
158
|
+
@logger.heading("Checking binary dependencies")
|
159
|
+
tmp_errors = check_binaries
|
160
|
+
if tmp_errors > 0
|
161
|
+
@errors += tmp_errors
|
162
|
+
@logger.error("#{tmp_errors} binaries not found!")
|
163
|
+
else
|
164
|
+
@logger.notice("All binaries found.")
|
165
|
+
end
|
166
|
+
|
167
|
+
@logger.heading("Checking filesystem dependencies")
|
168
|
+
tmp_errors = check_filesystem
|
169
|
+
if tmp_errors > 0
|
170
|
+
@errors += tmp_errors
|
171
|
+
@logger.error("#{tmp_errors} files/directories not found!")
|
172
|
+
else
|
173
|
+
@logger.notice("All files/directories found.")
|
174
|
+
end
|
175
|
+
|
176
|
+
@logger.heading("Checking URL dependencies")
|
177
|
+
tmp_errors = check_urls
|
178
|
+
if tmp_errors > 0
|
179
|
+
@errors += tmp_errors
|
180
|
+
@logger.error("#{tmp_errors} sites unavailable!")
|
181
|
+
else
|
182
|
+
@logger.notice("All sites found.")
|
183
|
+
end
|
182
184
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
185
|
+
@logger.heading("Checking gem dependencies")
|
186
|
+
#Initialize Gem Handler
|
187
|
+
gem_handler = GemHandler.new(self.configs["gems"],{
|
188
|
+
:install_all => @options[:gems],
|
189
|
+
:gem_path => @options[:gempath]
|
190
|
+
})
|
187
191
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
192
|
+
tmp_errors = 0
|
193
|
+
gem_handler.each do |c_gem|
|
194
|
+
if c_gem.status != :installed
|
195
|
+
tmp_errors += 1
|
196
|
+
@logger.notice("#{c_gem.name} v. #{c_gem.version}:: #{c_gem.details}")
|
197
|
+
else
|
198
|
+
@logger.info("#{c_gem.name} v. #{c_gem.version} requirement met.")
|
194
199
|
end
|
200
|
+
end
|
201
|
+
if tmp_errors > 0
|
202
|
+
@errors += tmp_errors
|
203
|
+
@logger.error("#{tmp_errors} gems are missing!")
|
204
|
+
else
|
205
|
+
@logger.notice("All gems found.")
|
206
|
+
end
|
207
|
+
|
208
|
+
#Load the ruby scripts (not run yet)
|
209
|
+
@logger.heading("Loading Ruby test scripts")
|
210
|
+
tmp_errors = load_ruby_scripts
|
211
|
+
if tmp_errors > 0
|
212
|
+
@errors += tmp_errors
|
213
|
+
@logger.error("#{tmp_errors} scripts failed to load!")
|
214
|
+
else
|
215
|
+
@logger.notice("All scripts loaded successfully.")
|
216
|
+
end
|
195
217
|
|
196
|
-
|
197
|
-
|
198
|
-
|
218
|
+
#Run the ruby scripts
|
219
|
+
@logger.heading("Running ruby tests scripts")
|
220
|
+
tmp_errors = test_ruby_scripts
|
221
|
+
if tmp_errors > 0
|
222
|
+
@errors += tmp_errors
|
223
|
+
@logger.error("#{tmp_errors} ruby tests failed!")
|
224
|
+
else
|
225
|
+
@logger.notice("All ruby tests ran successfully.")
|
226
|
+
end
|
199
227
|
|
200
|
-
|
201
|
-
|
202
|
-
|
228
|
+
#@logger.heading("Running shell tests scripts")
|
229
|
+
#tmp_errors = check_shell_scripts
|
230
|
+
#if tmp_errors > 0
|
231
|
+
# @errors += tmp_errors
|
232
|
+
# @logger.error("#{tmp_errors} shell tests failed!")
|
233
|
+
#else
|
234
|
+
# @logger.info("All shell tests ran successfully.")
|
235
|
+
#end
|
236
|
+
|
237
|
+
@logger.heading
|
238
|
+
@logger.heading("RESULTS")
|
203
239
|
|
204
|
-
|
205
|
-
|
206
|
-
|
240
|
+
@logger.info("Total Warnings: #{@warnings}")
|
241
|
+
@logger.info("Total Errors: #{@errors}")
|
242
|
+
@logger.info("Checked in #{Time.now.to_f-start_time.to_f}s")
|
207
243
|
|
208
|
-
|
209
|
-
section("RESULTS")
|
210
|
-
record("Total Warnings #{@warnings}",(@warnings > 0) ? :warning : :info)
|
211
|
-
record("Total Errors: #{@errors}",(@errors > 0) ? :error : :info)
|
212
|
-
record("Checked in #{Time.now.to_f-start_time.to_f}s",:info)
|
213
|
-
section
|
244
|
+
@logger.heading
|
214
245
|
|
215
246
|
#Status via growlnotify
|
216
247
|
if @options[:growl]
|
@@ -223,54 +254,9 @@ module RippleNetworks
|
|
223
254
|
end
|
224
255
|
|
225
256
|
unload
|
226
|
-
@
|
257
|
+
@logger.close
|
227
258
|
end
|
228
|
-
|
229
|
-
|
230
|
-
=begin rdoc
|
231
|
-
*Name*:: record
|
232
|
-
*Access*:: public
|
233
|
-
*Description*:: Record message to log
|
234
|
-
*Last_Edited*:: Wed Dec 12 15:37:21 PST 2007
|
235
|
-
===Parameters
|
236
|
-
* Name: level
|
237
|
-
* Description: Message level :error, :warning, :info, :none
|
238
|
-
* Datatype: Symbol
|
239
|
-
* Default: :info
|
240
|
-
* Required: false
|
241
|
-
=end
|
242
|
-
def record(msg,level=:none)
|
243
|
-
if [:error,:warning,:info,:fatal].include? level
|
244
|
-
msg = %{#{level.to_s.upcase}: #{msg}}
|
245
|
-
end
|
246
|
-
|
247
|
-
case level
|
248
|
-
when :error
|
249
|
-
@errors += 1
|
250
|
-
when :warning
|
251
|
-
@warnings += 1
|
252
|
-
end
|
253
|
-
|
254
|
-
@log_file.puts msg
|
255
|
-
|
256
|
-
if @options[:verbose]
|
257
|
-
case level
|
258
|
-
when :info
|
259
|
-
msg = "\e[37m#{msg}\e[0m"
|
260
|
-
when :error
|
261
|
-
msg = "\e[31m#{msg}\e[0m"
|
262
|
-
when :warning
|
263
|
-
msg = "\e[33m#{msg}\e[0m"
|
264
|
-
when :fatal
|
265
|
-
msg = "\e[1m\e[5m#{msg}\e[0m"
|
266
|
-
end
|
267
|
-
|
268
|
-
puts msg
|
269
|
-
|
270
|
-
Kernel.exit if level == :fatal
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
259
|
+
|
274
260
|
|
275
261
|
private
|
276
262
|
|
@@ -314,23 +300,6 @@ module RippleNetworks
|
|
314
300
|
gmsg += %{ --image #{File.join(LIB_DIRECTORY,"..","images",img)}} unless img.nil?
|
315
301
|
%x{#{gmsg}}
|
316
302
|
end
|
317
|
-
|
318
|
-
|
319
|
-
=begin rdoc
|
320
|
-
*Name*:: section
|
321
|
-
*Access*:: private
|
322
|
-
*Description*:: Display a section seperator
|
323
|
-
*Last_Edited*:: Mon Dec 17 10:45:52 PST 2007
|
324
|
-
===Parameters
|
325
|
-
* Name: title
|
326
|
-
* Description: Puts a title in the seperator
|
327
|
-
* Datatype: string
|
328
|
-
* Default: None
|
329
|
-
* Required: False
|
330
|
-
=end
|
331
|
-
def section(title="")
|
332
|
-
record %{#{title.center(60,"-") }}
|
333
|
-
end
|
334
303
|
|
335
304
|
|
336
305
|
=begin rdoc
|
@@ -348,28 +317,15 @@ module RippleNetworks
|
|
348
317
|
|
349
318
|
if @options[:growl]
|
350
319
|
unless DepChecker.has_binary? "growlnotify"
|
351
|
-
|
320
|
+
@logger.warning "Could not locate: `growlnotify`"
|
352
321
|
end
|
353
322
|
end
|
354
323
|
return true
|
355
324
|
else
|
356
|
-
|
325
|
+
@logger.error "Could not locate: `which`; required for binaries dependencies\n\tbinaries.yml will be skipped!!!"
|
357
326
|
return false
|
358
327
|
end
|
359
328
|
end
|
360
|
-
|
361
|
-
|
362
|
-
=begin rdoc
|
363
|
-
*Name*:: flush_log!
|
364
|
-
*Access*:: private
|
365
|
-
*Description*:: Flushes log file if it exists
|
366
|
-
*Last_Edited*:: Wed Dec 12 15:04:11 PST 2007
|
367
|
-
=end
|
368
|
-
def flush_log!
|
369
|
-
File.truncate(@options[:log],0) if File.exists? @options[:log]
|
370
|
-
#File.unlink @options[:log] if File.exists? @options[:log]
|
371
|
-
#FileUtils.touch @options[:log]
|
372
|
-
end
|
373
329
|
|
374
330
|
|
375
331
|
=begin rdoc
|
@@ -392,16 +348,18 @@ module RippleNetworks
|
|
392
348
|
#TODO Mute output from requires, ie "puts"
|
393
349
|
#@@@ Rescue block doesn't seem to be catching error.
|
394
350
|
require klass
|
395
|
-
|
351
|
+
@logger.info("FOUND: #{klass}")
|
396
352
|
rescue LoadError => e
|
397
353
|
case mode
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
354
|
+
when "preload"
|
355
|
+
@logger.fatal("NOT FOUND: #{klass}")
|
356
|
+
Kernel.exit
|
357
|
+
when "classes"
|
358
|
+
errors += 1
|
359
|
+
@logger.error("NOT FOUND: #{klass}")
|
360
|
+
else
|
361
|
+
@logger.fatal("Invalid class_loader mode")
|
362
|
+
Kernel.exit
|
405
363
|
end
|
406
364
|
end
|
407
365
|
end
|
@@ -422,10 +380,10 @@ module RippleNetworks
|
|
422
380
|
if @which_installed
|
423
381
|
@configs["binaries"].each do |binary|
|
424
382
|
if DepChecker.has_binary? binary
|
425
|
-
|
383
|
+
@logger.info("INSTALLED: #{binary}")
|
426
384
|
else
|
427
385
|
errors += 1
|
428
|
-
|
386
|
+
@logger.error("NOT FOUND: #{binary}")
|
429
387
|
end
|
430
388
|
end
|
431
389
|
|
@@ -446,13 +404,13 @@ module RippleNetworks
|
|
446
404
|
|
447
405
|
@configs["filesystem"].each do |path|
|
448
406
|
if File.file?(path)
|
449
|
-
|
407
|
+
@logger.info("FOUND (file): #{path}")
|
450
408
|
elsif File.directory?(path)
|
451
|
-
|
409
|
+
@logger.info("FOUND (directory): #{path}")
|
452
410
|
elsif File.exists?(path)
|
453
|
-
|
411
|
+
@logger.info("FOUND: #{path}")
|
454
412
|
else
|
455
|
-
|
413
|
+
@logger.error("NOT FOUND: #{path}")
|
456
414
|
errors += 1
|
457
415
|
end
|
458
416
|
end
|
@@ -482,16 +440,20 @@ module RippleNetworks
|
|
482
440
|
http_code = response.code.to_i
|
483
441
|
|
484
442
|
if @options[:strict] && http_code == 200
|
485
|
-
|
443
|
+
@logger.info("CONNECTED (#{http_code}): #{uri}")
|
486
444
|
elsif http_code >= 200 && http_code < 300
|
487
|
-
|
445
|
+
if (http_code != 200)
|
446
|
+
@logger.warning("CONNECTED (#{http_code}): #{uri}")
|
447
|
+
else
|
448
|
+
@logger.info("CONNECTED (#{http_code}): #{uri}")
|
449
|
+
end
|
488
450
|
else
|
489
451
|
errors += 1
|
490
|
-
|
452
|
+
@logger.error("UNAVAILABLE (#{http_code}): #{uri}")
|
491
453
|
end
|
492
454
|
rescue Exception => e
|
493
455
|
errors += 1
|
494
|
-
|
456
|
+
@logger.error("An exception occurred: #{e.message} while connecting to: #{uri}")
|
495
457
|
end
|
496
458
|
end
|
497
459
|
|
@@ -509,8 +471,8 @@ module RippleNetworks
|
|
509
471
|
begin
|
510
472
|
require pre_script if File.exists? pre_script
|
511
473
|
rescue
|
512
|
-
|
513
|
-
|
474
|
+
@logger.fatal "Failed to load: #{pre_script}"
|
475
|
+
Kernel.exit
|
514
476
|
end
|
515
477
|
|
516
478
|
Dir.new(scripts_path).each { |script|
|
@@ -524,8 +486,8 @@ module RippleNetworks
|
|
524
486
|
begin
|
525
487
|
require s if File.exists? s
|
526
488
|
rescue
|
527
|
-
|
528
|
-
|
489
|
+
@logger.fatal "Failed to load: #{s}"
|
490
|
+
Kernel.exit
|
529
491
|
end
|
530
492
|
}
|
531
493
|
|
@@ -537,12 +499,13 @@ module RippleNetworks
|
|
537
499
|
begin
|
538
500
|
require post_script if File.exists? post_script
|
539
501
|
rescue
|
540
|
-
|
541
|
-
|
502
|
+
@logger.fatal "Failed to load: #{pre_script}"
|
503
|
+
Kernel.exit
|
542
504
|
end
|
543
505
|
rescue Exception => e
|
544
|
-
|
545
|
-
|
506
|
+
@logger.fatal(e)
|
507
|
+
@logger.fatal "Script directory not found, try running 'warning-shot --templates=PATH'"
|
508
|
+
Kernel.exit
|
546
509
|
end
|
547
510
|
|
548
511
|
return errors
|
@@ -556,15 +519,16 @@ module RippleNetworks
|
|
556
519
|
result, message = test.run()
|
557
520
|
|
558
521
|
unless result
|
559
|
-
|
560
|
-
|
522
|
+
@logger.error %{#{test.class} test failed!}
|
523
|
+
@logger.notice(%{Message from #{test.class} test: #{message}}) unless message.nil?
|
561
524
|
errors += 1
|
562
525
|
else
|
563
|
-
|
564
|
-
|
526
|
+
@logger.info(%{#{test.class} test passed!})
|
527
|
+
@logger.notice(%{Message from #{test.class} test: #{message}}) unless message.nil?
|
565
528
|
end
|
566
529
|
rescue Exception => e
|
567
|
-
|
530
|
+
@logger.fatal %{An error occured while processing: #{test.class}\n#{e}}
|
531
|
+
@logger.notice "This test may be inconclusive..."
|
568
532
|
errors += 1
|
569
533
|
end
|
570
534
|
end
|
data/lib/warning_shot/logger.rb
CHANGED
@@ -2,16 +2,99 @@
|
|
2
2
|
module RippleNetworks
|
3
3
|
module WarningShot
|
4
4
|
class Logger
|
5
|
+
#Set up CLEAR and Windows Add'l requirement
|
6
|
+
if PLATFORM =~ /win32/
|
7
|
+
CLEAR = `cls`
|
8
|
+
begin
|
9
|
+
require 'Win32/Console/ANSI'
|
10
|
+
rescue LoadError => e
|
11
|
+
puts "Run: 'gem install win32console' for colored output"
|
12
|
+
end
|
13
|
+
else
|
14
|
+
CLEAR = `clear`
|
15
|
+
end
|
16
|
+
|
5
17
|
|
6
|
-
|
18
|
+
ESCAPE_SEQ = {
|
19
|
+
:notice => "\e[37m%s\e[0m",
|
20
|
+
:warning => "\e[33m%s\e[0m",
|
21
|
+
:debug => "\e[34m%s\e[0m",
|
22
|
+
:error => "\e[31m%s\e[0m",
|
23
|
+
:fatal => "\e[1m\e[5m%s\e[0m"
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
DEFAULTS = {
|
28
|
+
:verbose => false,
|
29
|
+
:flush => false
|
30
|
+
}
|
31
|
+
|
32
|
+
def initialize(path,opts={})
|
33
|
+
options = DEFAULTS.merge(opts)
|
34
|
+
@verbose = options[:verbose]
|
35
|
+
|
36
|
+
@log_file = File.open(path,"a+")
|
37
|
+
|
38
|
+
#Flush log
|
39
|
+
flush_log!(path) if options[:flush]
|
40
|
+
|
41
|
+
#Clear console
|
42
|
+
puts CLEAR if @verbose
|
43
|
+
end
|
44
|
+
|
45
|
+
def heading(title="");
|
46
|
+
msg = %{#{title.center(60,"-") }}
|
47
|
+
@log_file.puts msg
|
48
|
+
puts msg if @verbose
|
49
|
+
end
|
50
|
+
|
51
|
+
def close()
|
52
|
+
@log_file.close unless @log_file.closed?
|
53
|
+
end
|
54
|
+
|
55
|
+
def info(msg)
|
56
|
+
@log_file.puts msg
|
57
|
+
puts msg if @verbose
|
58
|
+
end
|
59
|
+
|
60
|
+
def notice(msg)
|
61
|
+
frm_msg = output_msg(:notice,msg)
|
62
|
+
@log_file.puts frm_msg
|
63
|
+
puts frm_msg if @verbose
|
64
|
+
end
|
65
|
+
|
66
|
+
def debug(msg)
|
67
|
+
frm_msg = output_msg(:debug,msg)
|
68
|
+
@log_file.puts frm_msg
|
69
|
+
puts frm_msg if @verbose
|
70
|
+
end
|
71
|
+
|
72
|
+
def error(msg)
|
73
|
+
frm_msg = output_msg(:error,msg)
|
74
|
+
@log_file.puts frm_msg
|
75
|
+
puts frm_msg if @verbose
|
76
|
+
end
|
77
|
+
|
78
|
+
def warning(msg)
|
79
|
+
frm_msg = output_msg(:warning,msg)
|
80
|
+
@log_file.puts frm_msg
|
81
|
+
puts frm_msg if @verbose
|
82
|
+
end
|
83
|
+
|
84
|
+
def fatal(msg)
|
85
|
+
frm_msg = output_msg(:fatal,msg)
|
86
|
+
@log_file.puts frm_msg
|
87
|
+
puts frm_msg if @verbose
|
88
|
+
end
|
7
89
|
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
def fatal();end;
|
90
|
+
private
|
91
|
+
def output_msg(type,msg)
|
92
|
+
frm_msg = sprintf(ESCAPE_SEQ[type],%{[#{type.to_s.upcase}]\t #{msg}})
|
93
|
+
end
|
13
94
|
|
14
|
-
def
|
95
|
+
def flush_log!(log_file)
|
96
|
+
File.truncate(log_file,0) if File.exists? log_file
|
97
|
+
end
|
15
98
|
end
|
16
99
|
end
|
17
100
|
end
|
data/lib/warning_shot/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>warning_shot</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/warning_shot"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/warning_shot" class="numbers">0.9.
|
36
|
+
<a href="http://rubyforge.org/projects/warning_shot" class="numbers">0.9.3</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘warning_shot’</h1>
|
39
39
|
|