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
404 405 406 |
# File 'lib/parallelpipes.rb', line 404 def verbosity @verbosity end |
Class Method Details
.clean_up ⇒ Object
Deletes the log file if there is one
426 427 428 |
# File 'lib/parallelpipes.rb', line 426 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).
420 421 422 |
# File 'lib/parallelpipes.rb', line 420 def self.io=(_io) @@log_io = _io end |
.log_file ⇒ Object
407 408 409 |
# File 'lib/parallelpipes.rb', line 407 def self.log_file @@log_file end |
.log_file=(file) ⇒ Object
Give a log file name for logging.
413 414 415 416 |
# File 'lib/parallelpipes.rb', line 413 def self.log_file=(file) @@log_file=file # @@io = nil end |
Instance Method Details
#log(options, *messages) ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/parallelpipes.rb', line 479 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 |