aboutsummaryrefslogtreecommitdiff
path: root/logger.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-20 03:30:09 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-20 03:30:09 -0700
commit7e7aa3278a9e478b02eb152575fb00ee0802ac81 (patch)
tree4f7a6c1fafeae67500d3bfba5321ea5e2e571f18 /logger.rb
parented09327eac899b9d5a1f782616747ca13c4806b1 (diff)
downloaddinobot-7e7aa3278a9e478b02eb152575fb00ee0802ac81.tar.gz
dinobot-7e7aa3278a9e478b02eb152575fb00ee0802ac81.tar.xz
Add singleton logger class.
Diffstat (limited to 'logger.rb')
-rw-r--r--logger.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/logger.rb b/logger.rb
new file mode 100644
index 0000000..f84c157
--- /dev/null
+++ b/logger.rb
@@ -0,0 +1,48 @@
+module Dinobot
+ class Logger
+ @@instance = nil
+ @@mutex = Mutex.new
+
+ def in(*lines)
+ str = lines.join("\n")
+
+ puts str.gsub(/^/, "\e[32m<<\e[0m ")
+ end
+
+ def out(*lines)
+ str = lines.join("\n")
+
+ puts str.gsub(/^/, "\e[36m>>\e[0m ")
+ end
+
+ def error(*lines)
+ str = lines.join("\n")
+
+ puts str.gsub(/^/, "\e[31m!!\e[0m ")
+ end
+
+ def info(*lines)
+ str = lines.join("\n")
+
+ puts str.gsub(/^/, "\e[33m==\e[0m ")
+ end
+
+ def indent(*lines)
+ str = lines.join("\n")
+
+ puts str.gsub(/^/, ' ')
+ end
+
+ class << self
+ def instance
+ return @@instance if @@instance
+
+ @@mutex.synchronize do
+ @@instance ||= new
+ end
+ end
+ end
+
+ private_class_method :allocate, :new
+ end
+end