Module: Output
- Defined in:
- lib/start.rb
Overview
ログ出力
Class Method Summary collapse
Class Method Details
.console_and_file(output_file, stdout = true) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/start.rb', line 35 def self.console_and_file(output_file, stdout = true) begin defout = File.new(output_file, "a+") rescue puts $! puts $@ return nil end class << defout alias_method :write_org, :write def initialize(stdout) @stdout = false end attr_accessor :stdout def puts(str) STDOUT.write(str.to_s + "\n") if @stdout self.write_org(str.to_s + "\n") self.flush end def write(str) STDOUT.write(str) if @stdout self.write_org(str) self.flush end end $stdout = defout $stdout.stdout = stdout end |