Class: WeChat::Bot::Logger
- Inherits:
-
Object
- Object
- WeChat::Bot::Logger
- Defined in:
- lib/wechat/bot/logger.rb
Constant Summary collapse
- LEVELS =
[:verbose, :debug, :info, :warn, :error, :fatal]
Instance Attribute Summary collapse
- #level ⇒ Symbol
- #mutex ⇒ Mutex readonly
- #output ⇒ IO readonly
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #fatal(exception) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(output, bot) ⇒ Logger
constructor
A new instance of Logger.
- #log(level, message) ⇒ Object
- #verbose(message) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(output, bot) ⇒ Logger
Returns a new instance of Logger.
16 17 18 19 20 21 |
# File 'lib/wechat/bot/logger.rb', line 16 def initialize(output, bot) @output = output @bot = bot @mutex = Mutex.new @level = :info end |
Instance Attribute Details
#level ⇒ Symbol
8 9 10 |
# File 'lib/wechat/bot/logger.rb', line 8 def level @level end |
#mutex ⇒ Mutex (readonly)
11 12 13 |
# File 'lib/wechat/bot/logger.rb', line 11 def mutex @mutex end |
#output ⇒ IO (readonly)
14 15 16 |
# File 'lib/wechat/bot/logger.rb', line 14 def output @output end |
Instance Method Details
#debug(message) ⇒ Object
27 28 29 |
# File 'lib/wechat/bot/logger.rb', line 27 def debug() log(:debug, ) end |
#error(message) ⇒ Object
39 40 41 |
# File 'lib/wechat/bot/logger.rb', line 39 def error() log(:error, ) end |
#fatal(exception) ⇒ Object
43 44 45 46 47 |
# File 'lib/wechat/bot/logger.rb', line 43 def fatal(exception) = ["#{exception.backtrace.first}: #{exception.} (#{exception.class})"] .concat(exception.backtrace[1..-1].map {|s| "\t" + s}) log(:fatal, .join("\n")) end |
#info(message) ⇒ Object
31 32 33 |
# File 'lib/wechat/bot/logger.rb', line 31 def info() log(:info, ) end |
#log(level, message) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/wechat/bot/logger.rb', line 49 def log(level, ) return unless can_log?(level) return if .to_s.empty? @mutex.synchronize do = (format_general(), level) @output.puts end end |
#verbose(message) ⇒ Object
23 24 25 |
# File 'lib/wechat/bot/logger.rb', line 23 def verbose() log(:verbose, ) end |
#warn(message) ⇒ Object
35 36 37 |
# File 'lib/wechat/bot/logger.rb', line 35 def warn() log(:warn, ) end |