lib/ginst/logger.rb in ginst-2009.11.24 vs lib/ginst/logger.rb in ginst-2009.12.8
- old
+ new
@@ -1,31 +1,34 @@
class Ginst::Logger
def initialize(file)
- @filename = file
- @file = File.open(file,'a')
- @file.sync = true
-
+ @filename = file
ObjectSpace.define_finalizer(self) do
puts self.class.to_s
puts 'Cerrando log file'
@file.close
end
end
def log(msg,acaller = nil)
acaller ||= caller
msg = format_msg(msg,acaller)
- @file.write(msg)
+ write(msg)
msg
end
def format_msg(msg, caller)
call = File.basename(caller.first).split(":")[0..1].join(":")
"[%s %s] %s\n" % [Time.now.to_s, call, msg]
+ end
+ private
+ def write(msg)
+ File.open(@filename,'a') do |f|
+ f.write msg
+ end
end
end
\ No newline at end of file