lib/scout/log.rb in scout-essentials-1.3.1 vs lib/scout/log.rb in scout-essentials-1.6.0
- old
+ new
@@ -107,24 +107,23 @@
end
end
def self.logfile(file=nil)
if file.nil?
- @logfile ||= nil
+ @@logfile = nil
else
case file
when String
- @logfile = File.open(file, :mode => 'a')
- @logfile.sync = true
+ @@logfile = File.open(file, :mode => 'a')
+ @@logfile.sync = true
when IO, File
- @logfile = file
+ @@logfile = file
else
raise "Unkown logfile format: #{file.inspect}"
end
end
end
-
def self.up_lines(num = 1)
nocolor ? "" : "\033[#{num+1}F\033[2K"
end
def self.down_lines(num = 1)
@@ -140,30 +139,30 @@
end
MUTEX = Mutex.new
def self.log_write(str)
MUTEX.synchronize do
- if logfile.nil?
+ if defined?(@@logfile) && @@logfile
+ @@logfile.write str
+ else
begin
STDERR.write str
rescue
end
- else
- logfile.write str
end
end
end
def self.log_puts(str)
MUTEX.synchronize do
- if logfile.nil?
+ if defined?(@@logfile) && @@logfile
+ @@logfile.puts str
+ else
begin
STDERR.puts str
rescue
end
- else
- logfile.puts str
end
end
end
LAST = "log"
@@ -307,9 +306,10 @@
tsv.fields.zip(values).each do |field,value|
log_puts Log.color(:magenta, field + ": ") + (Array === value ? value * ", " : value.to_s)
end
end
end
+ Log::LAST.replace "log"
end
def self.stack(stack)
if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
log_puts Log.color :magenta, "Stack trace [#{Process.pid}]: " << Log.last_caller(caller)