summary refs log tree commit diff stats
path: root/code/debug.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-04-10 00:00:00 +0200
committerhut <hut@lavabit.com>2009-04-10 00:00:00 +0200
commit34bfb32ecf2cea5e5de95980beedb681139d9c01 (patch)
tree68acd3339f575782b5ebccbb70d8c1efd0dffc62 /code/debug.rb
parentadfea091f816cc2f4007e99b6b2be35a821857da (diff)
downloadranger-34bfb32ecf2cea5e5de95980beedb681139d9c01.tar.gz
new minor version v0.2.0
Diffstat (limited to 'code/debug.rb')
-rw-r--r--code/debug.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/code/debug.rb b/code/debug.rb
new file mode 100644
index 00000000..6261ed0e
--- /dev/null
+++ b/code/debug.rb
@@ -0,0 +1,67 @@
+
+require 'pp'
+
+module Debug
+	@@logfile = '/tmp/errorlog'
+	@@logstream = File.open(@@logfile, 'a')
+
+	def self.write(str)
+		@@logstream.write(str)
+		@@logstream.flush
+		return str
+	end
+	def self.puts(str)
+		@@logstream.puts(str)
+		@@logstream.flush
+		return str
+	end
+
+	def try(&block)
+		return unless block
+		begin
+			yield
+		rescue Exception
+		end
+	end
+
+	if LOG_LEVEL > 0
+		def __log__(obj, level)
+			if level <= LOG_LEVEL
+				obj = obj.nil? ? "checkpoint at #{Time.now}" : obj
+				Debug.puts(obj)
+			end
+		end
+		def __logpp__(obj, level)
+			if level <= LOG_LEVEL
+				$stdout = @@logstream
+				pp obj
+				$stdout.flush
+				$stdout = STDOUT
+			end
+		end
+
+		def logfatal(obj = nil) __log__(obj, 1) end
+		def logppfatal(obj = nil) __logpp__(obj, 1) end
+
+		def logerr(obj = nil) __log__(obj, 2) end
+		def logpperr(obj = nil) __logpp__(obj, 2) end
+
+		def log(obj = nil) __log__(obj, 3) end
+		def logpp(obj = nil) __logpp__(obj, 3) end
+
+		def trace() __logpp__(caller, 3) end
+	else
+		def __log__(a, b) end
+		def __logpp__(a, b) end
+
+		def logfatal(a=nil) end
+		def logppfatal(a=nil) end
+
+		def logerr(a=nil) end
+		def logpperr(a=nil) end
+
+		def log(a=nil) end
+		def logpp(a=nil) end
+		def trace() end
+	end
+end