Class: LLT::Logger
- Inherits:
-
Object
- Object
- LLT::Logger
- Defined in:
- lib/llt/logger.rb,
lib/llt/logger/version.rb
Constant Summary collapse
- LEVELS =
%w{ error info parser cf morph debug }
- DEFAULT_LEVEL =
Numeric vals 0 1 2 3 4 5
1
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.loggers ⇒ Object
readonly
Returns the value of attribute loggers.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
- .clear ⇒ Object
- .count(mapper = :count) ⇒ Object
- .count_errors ⇒ Object
- .count_warnings ⇒ Object
- .errors ⇒ Object
- .level(n = nil) ⇒ Object
- .level=(lev) ⇒ Object
- .messages_that_match(regexp) ⇒ Object
- .new(*args) ⇒ Object
- .normalized_level(lev) ⇒ Object
- .warnings ⇒ Object
Instance Method Summary collapse
- #bare(message, indent = 0) ⇒ Object
- #cf(message, indent = "") ⇒ Object
- #count ⇒ Object
- #debug(message, indent = "") ⇒ Object
- #error(message, indent = "") ⇒ Object
- #info(message, indent = "") ⇒ Object
-
#initialize(title = "", indent = "", default: :info) ⇒ Logger
constructor
A new instance of Logger.
- #log(*args) ⇒ Object
- #morph(message, indent = "") ⇒ Object
- #parser(message, indent = "") ⇒ Object
- #warning(message, indent = "") ⇒ Object
Constructor Details
#initialize(title = "", indent = "", default: :info) ⇒ Logger
Returns a new instance of Logger.
88 89 90 91 92 93 94 95 |
# File 'lib/llt/logger.rb', line 88 def initialize(title = "", indent = "", default: :info) @title = title @indent = to_whitespace(indent) @default = default @logs = [] @errors = 0 @warnings = 0 end |
Class Attribute Details
.loggers ⇒ Object (readonly)
Returns the value of attribute loggers.
14 15 16 |
# File 'lib/llt/logger.rb', line 14 def loggers @loggers end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
86 87 88 |
# File 'lib/llt/logger.rb', line 86 def errors @errors end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
86 87 88 |
# File 'lib/llt/logger.rb', line 86 def logs @logs end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
86 87 88 |
# File 'lib/llt/logger.rb', line 86 def title @title end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
86 87 88 |
# File 'lib/llt/logger.rb', line 86 def warnings @warnings end |
Class Method Details
.clear ⇒ Object
39 40 41 |
# File 'lib/llt/logger.rb', line 39 def clear @loggers.clear end |
.count(mapper = :count) ⇒ Object
43 44 45 |
# File 'lib/llt/logger.rb', line 43 def count(mapper = :count) @loggers.map(&mapper).inject(:+) end |
.count_errors ⇒ Object
59 60 61 |
# File 'lib/llt/logger.rb', line 59 def count_errors count(:errors) end |
.count_warnings ⇒ Object
63 64 65 |
# File 'lib/llt/logger.rb', line 63 def count_warnings count(:warnings) end |
.errors ⇒ Object
47 48 49 |
# File 'lib/llt/logger.rb', line 47 def errors .select { || =~ /ERROR!/ } end |
.level(n = nil) ⇒ Object
28 29 30 31 |
# File 'lib/llt/logger.rb', line 28 def level(n = nil) return nil if @level.nil? n ? n <= @level : @level end |
.level=(lev) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/llt/logger.rb', line 16 def level=(lev) return @level = nil if lev.nil? l = normalized_level(lev) unless valid_level?(l) l = @level || DEFAULT_LEVEL # DEFAULT_LEVEL catches invalid levels defined through the env var puts "LOG LEVEL ERROR".red + " #{lev} is unknown - falling back to #{l}" end @level = l end |
.messages_that_match(regexp) ⇒ Object
55 56 57 |
# File 'lib/llt/logger.rb', line 55 def (regexp) .select { || =~ regexp } end |
.new(*args) ⇒ Object
33 34 35 36 37 |
# File 'lib/llt/logger.rb', line 33 def new(*args) new_logger = super @loggers << new_logger new_logger end |
.normalized_level(lev) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/llt/logger.rb', line 67 def normalized_level(lev) if lev.is_a? Fixnum lev else LEVELS.index(lev.to_s) || -1 # -1 to fail the valid_level? test end end |
.warnings ⇒ Object
51 52 53 |
# File 'lib/llt/logger.rb', line 51 def warnings .select { || =~ /WARNING!/ } end |
Instance Method Details
#bare(message, indent = 0) ⇒ Object
138 139 140 141 |
# File 'lib/llt/logger.rb', line 138 def (, indent = 0) lev = Logger.normalized_level(@default) puts "#{to_whitespace(indent)}#{}" if level(lev) end |
#cf(message, indent = "") ⇒ Object
126 127 128 |
# File 'lib/llt/logger.rb', line 126 def cf(, indent = "") (, indent) if level(3) end |
#count ⇒ Object
143 144 145 |
# File 'lib/llt/logger.rb', line 143 def count @logs.count end |
#debug(message, indent = "") ⇒ Object
134 135 136 |
# File 'lib/llt/logger.rb', line 134 def debug(, indent = "") (, indent) if level(5) end |
#error(message, indent = "") ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/llt/logger.rb', line 102 def error(, indent = "") = "ERROR! #{}".light_red if level(0) (, indent) @errors += 1 end end |
#info(message, indent = "") ⇒ Object
118 119 120 |
# File 'lib/llt/logger.rb', line 118 def info(, indent = "") (, indent) if level(1) end |
#log(*args) ⇒ Object
97 98 99 100 |
# File 'lib/llt/logger.rb', line 97 def log(*args) send(@default, *args) # TODO Exception Handling end |
#morph(message, indent = "") ⇒ Object
130 131 132 |
# File 'lib/llt/logger.rb', line 130 def morph(, indent = "") (, indent) if level(4) end |
#parser(message, indent = "") ⇒ Object
122 123 124 |
# File 'lib/llt/logger.rb', line 122 def parser(, indent = "") (, indent) if level(2) end |
#warning(message, indent = "") ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/llt/logger.rb', line 110 def warning(, indent = "") = "WARNING! #{}".yellow if level(1) (, indent) @warnings += 1 end end |