class BitGirder::Core::BitGirderLogger
Constants
- CODE
Our log levels
- CONSOLE
- DEFAULT
- WARN
Attributes
level[R]
Public Class Methods
get_logger()
click to toggle source
# File lib/bitgirder/core.rb, line 134 def self.get_logger @logger end
is_debug_env_set?()
click to toggle source
# File lib/bitgirder/core.rb, line 127 def self.is_debug_env_set? ( ENV[ ENV_BITGIRDER_DEBUG ] or "" ).strip =~ /^(true|yes)$/ end
new()
click to toggle source
# File lib/bitgirder/core.rb, line 51 def initialize @lock = Mutex.new end
Private Class Methods
level_of( lev )
click to toggle source
# File lib/bitgirder/core.rb, line 77 def self.level_of( lev ) case lev when CODE then 1 when CONSOLE then 2 when WARN then 3 else raise "Invalid level: #{lev}" end end
Public Instance Methods
code( *argv )
click to toggle source
# File lib/bitgirder/core.rb, line 96 def code( *argv ) send_msg( CODE, Time.now, argv ) end
Also aliased as: debug
console( *argv )
click to toggle source
# File lib/bitgirder/core.rb, line 108 def console( *argv ) send_msg( CONSOLE, Time.now, argv ) end
is_debug?()
click to toggle source
# File lib/bitgirder/core.rb, line 113 def is_debug? @level == CODE end
level=( lev )
click to toggle source
# File lib/bitgirder/core.rb, line 118 def level=( lev ) @level = case lev when CODE, CONSOLE, WARN then lev else raise ArgumentError, "Unknown level: #{lev}" end end
warn( *argv )
click to toggle source
# File lib/bitgirder/core.rb, line 103 def warn( *argv ) send_msg( WARN, Time.now, argv ) end
Private Instance Methods
make_msg( argv )
click to toggle source
makes a string msg from argv, which can either be an exception and a message or just a message
# File lib/bitgirder/core.rb, line 58 def make_msg( argv ) case len = argv.length when 1 then argv.shift when 2 e, msg = *argv msg << "\n" << e.message.to_s bt = e.backtrace ( msg << "\n" << bt.join( "\n" ) ) if bt msg else raise ArgumentError, "Wrong number of arguments: #{len}" end end
send_msg( lev, time, argv )
click to toggle source
# File lib/bitgirder/core.rb, line 87 def send_msg( lev, time, argv ) if self.class.level_of( lev ) >= self.class.level_of( @level ) str = make_msg( argv ) @lock.synchronize { puts "[#{time.iso8601( 6 )}]: #{lev}: #{str}" } end end