lib/logging.rb in runeblog-0.2.43 vs lib/logging.rb in runeblog-0.2.44
- old
+ new
@@ -1,11 +1,20 @@
unless self.respond_to?("log!")
$logging = true
$log = File.new("/tmp/runeblog.log","w")
- def log!(str: "", enter: nil, args: [], pwd: false, dir: false)
+ def outlog(str = "", stderr: false)
+ $log.puts str
+ STDERR.puts str if stderr
+ end
+
+ def log!(str: "", enter: nil, args: [], pwd: false, dir: false, level: 0, stderr: false)
return unless $logging
+ @err_level ||= ENV['RUNEBLOG_ERROR_LEVEL']
+ @err_level ||= 0
+ return if level < @err_level
+
time = Time.now.strftime("%H:%M:%S")
meth = ""
meth = "#{enter}" if enter
@@ -15,19 +24,19 @@
source = "in #{source} (probably liveblog.rb)" if source.include? "(eval)"
str = " ... #{str}" unless str.empty?
indent = " "*12
- $log.puts "#{time} #{meth}#{para}"
- $log.puts "#{indent} #{str} " unless str.empty?
- $log.puts "#{indent} #{source}"
- $log.puts "#{indent} pwd = #{Dir.pwd} " if pwd
+ outlog "#{time} #{meth}#{para}"
+ outlog "#{indent} #{str} " unless str.empty?
+ outlog "#{indent} #{source}"
+ outlog "#{indent} pwd = #{Dir.pwd} " if pwd
if dir
files = (Dir.entries('.') - %w[. ..]).join(" ")
- $log.puts "#{indent} dir/* = #{files}"
+ outlog "#{indent} dir/* = #{files}"
end
-# $log.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
- $log.puts
+# outlog "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
+ outlog
$log.close
$log = File.new("/tmp/runeblog.log","a")
end
end