Module: PPipe::Log
Overview
A rough and ready logging module. Can be used independently of PPipe
Defined Under Namespace
Classes: BadLogOption, BadVerbosity
Constant Summary collapse
- @@log_file =
nil- @@log_io =
nil- @@log_group_options =
[:t, :v]
- @@log_individual_options =
[:i, :f, :c, :p]
- @@log_possible_options =
@@log_group_options + @@log_individual_options
Instance Attribute Summary collapse
-
#verbosity ⇒ Object
The verbosity of the object.
Class Method Summary collapse
-
.clean_up ⇒ Object
Deletes the log file if there is one.
-
.io=(_io) ⇒ Object
Give an io object for logging (overrides any file given for logging).
- .log_file ⇒ Object
-
.log_file=(file) ⇒ Object
Give a log file name for logging.
Instance Method Summary collapse
Instance Attribute Details
#verbosity ⇒ Object
The verbosity of the object. Only log calls with a verbosity level lower than or equal to the verbosity will execute
420 421 422 |
# File 'lib/parallelpipes.rb', line 420 def verbosity @verbosity end |
Class Method Details
.clean_up ⇒ Object
Deletes the log file if there is one
442 443 444 |
# File 'lib/parallelpipes.rb', line 442 def self.clean_up File.delete @@log_file if FileTest.exist? @@log_file end |
.io=(_io) ⇒ Object
Give an io object for logging (overrides any file given for logging).
436 437 438 |
# File 'lib/parallelpipes.rb', line 436 def self.io=(_io) @@log_io = _io end |
.log_file ⇒ Object
423 424 425 |
# File 'lib/parallelpipes.rb', line 423 def self.log_file @@log_file end |
.log_file=(file) ⇒ Object
Give a log file name for logging.
429 430 431 432 |
# File 'lib/parallelpipes.rb', line 429 def self.log_file=(file) @@log_file=file # @@io = nil end |
Instance Method Details
#log(options, *messages) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/parallelpipes.rb', line 495 def log(, *) return unless @@log_io or @@log_file raise BadVerbosity.new("#{@verbosity.class}: #{@verbosity.inspect}") unless @verbosity.class == Fixnum and @verbosity > -1 = = .to_s.split(//).map{|op| op.to_sym} if .class == String or .class == Symbol ||= [] if .include? :v @log_defaults ||= {} vi = .index(:v) used_v = nil unless [vi+1] and [vi+1].to_s =~ /^\d$/ return unless @verbosity >= (@log_defaults[( - [:v]).sort] or @log_defaults[( - [:v]).sort] or 9) .delete_at(vi) else # $stderr.puts "verbosity required is", options[vi+1].to_s.to_i, "verbosity is: ", @verbosity return unless @verbosity >= [vi+1].to_s.to_i .delete_at(vi) .delete_at(vi) end end raise BadLogOption.new("#{.inspect} --> " + ( - @@log_possible_options).inspect) if ( - @@log_possible_options).size > 0 .each do || = ( - @@log_group_options).inject(){|, option| = send(:log_convert_ + option, )} if @@log_io @@log_io.print .to_s + "\n" else File.open(@@log_file, 'a'){|file| file.print .to_s + "\n"} end end if .include? :t log("Traceback \n" + caller.join("\n")) end end |