Class: Log4r::Log4rTools

Inherits:
Object
  • Object
show all
Defined in:
lib/log4r/base.rb

Overview

Some common functions

Class Method Summary collapse

Class Method Details

.comma_split(string) ⇒ Object

Splits comma-delimited lists with arbitrary s padding



70
71
72
# File 'lib/log4r/base.rb', line 70

def self.comma_split(string)
  string.split(/\s*,\s*/).collect {|s| s.strip}
end

.decode_bool(hash, symbol, default) ⇒ Object

Shortcut for decoding ‘true’, ‘false’, true, false or nil into a bool from a hash parameter. E.g., it looks for true/false values for the keys ‘symbol’ and :symbol.



59
60
61
62
63
64
65
66
67
# File 'lib/log4r/base.rb', line 59

def self.decode_bool(hash, symbol, default)
  data = hash[symbol]
  data = hash[symbol.to_s] if data.nil?
  return case data
    when 'true',true then true
    when 'false',false then false
    else default
    end
end

.max_level_str_sizeObject

:nodoc:



49
50
51
52
53
# File 'lib/log4r/base.rb', line 49

def self.max_level_str_size #:nodoc:
  size = 0
  LNAMES.each {|i| size = i.length if i.length > size}
  size
end

.valid_level?(lev) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/log4r/base.rb', line 45

def self.valid_level?(lev)
  not lev.nil? and lev.kind_of?(Numeric) and lev >= ALL and lev <= OFF
end

.validate_level(level, depth = 0) ⇒ Object

Raises ArgumentError if level argument is an invalid level. Depth specifies how many trace entries to remove.



38
39
40
41
42
43
# File 'lib/log4r/base.rb', line 38

def self.validate_level(level, depth=0)
  unless valid_level?(level)
    raise ArgumentError, "Log level must be in 0..#{LEVELS}",
          caller[1..-(depth + 1)]
  end
end