Class: Dat::Logger::Log
- Inherits:
-
Object
- Object
- Dat::Logger::Log
- Defined in:
- lib/dat/logger.rb
Instance Method Summary collapse
-
#initialize(lid, opt) ⇒ Log
constructor
A new instance of Log.
- #log(str, is_literal = false) ⇒ Object
Constructor Details
#initialize(lid, opt) ⇒ Log
Returns a new instance of Log.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dat/logger.rb', line 17 def initialize(lid, opt) @timed = opt[:timed] if opt[:null] @file = File.open('/dev/null', 'w') elsif opt[:path] @file = File.open("#{opt[:path]}/dat-#{lid.to_s.gsub('/','|')}-#{Time.now.to_i}.log", "a") else @file = $stdout end @file.puts "#!/usr/bin/env ruby" @file.puts "$:.unshift('#{ENV["HOME"]}/Code/src/dat/lib/')" # TODO remove once installed as gem @file.puts "require 'dat'\n" @file.flush end |
Instance Method Details
#log(str, is_literal = false) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/dat/logger.rb', line 33 def log(str, is_literal=false) if is_literal @file.puts(str) else @file.puts( str.scan(/^.*/).map {|l| "# #{@timed ? "#{Time.now} " : ""}#{l}"}.join("\n")) end @file.flush end |