lib/template/start.rb in browser_app_base-0.0.9 vs lib/template/start.rb in browser_app_base-0.1.0

- old
+ new

@@ -10,37 +10,54 @@ require "json" require "facter" # ログ出力 module Output - def self.console_and_file(output_file) - defout = File.new(output_file, "a+") + 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") + STDOUT.write(str.to_s + "\n") if @stdout self.write_org(str.to_s + "\n") self.flush end def write(str) - STDOUT.write(str) + STDOUT.write(str) if @stdout self.write_org(str) self.flush end end $stdout = defout + $stdout.stdout = stdout end end -Output.console_and_file("log.txt") - # ディレクトリ移動 dir = File.dirname(File.expand_path(__FILE__)) FileUtils.cd dir +temp_dir = ENV["temp"] +temp_dir = "/tmp" if temp_dir == nil +puts "temp_dir=#{temp_dir}" +FileUtils.mkdir_p("#{temp_dir}/logs") +Output.console_and_file("#{temp_dir}/logs/app.log", true) + # 空きポートを取得 def get_unused_port s = TCPServer.open(0) port = s.addr[1] s.close @@ -60,12 +77,12 @@ buf = File.binread("js/main.js").toutf8 buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/") File.binwrite("js/main.js", buf) # index.htaの編集 -buf = File.binread("index.html").toutf8 +buf = File.binread("html/index.html").toutf8 buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/") -File.binwrite("index.html", buf) +File.binwrite("html/index.html", buf) begin Thread.start { puts "wait start web server" while true