Class: Loops::Logger::LoggerImplementation
- Inherits:
-
Logger
- Object
- Logger
- Loops::Logger::LoggerImplementation
- Defined in:
- lib/loops/logger.rb
Defined Under Namespace
Classes: Formatter
Instance Attribute Summary collapse
-
#colorful_logs ⇒ Object
Returns the value of attribute colorful_logs.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#write_to_console ⇒ Object
Returns the value of attribute write_to_console.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
- #color_errors(severity, line) ⇒ Object
-
#initialize(log_device, number_of_files = 10, max_file_size = 10 * 1024 * 1024, write_to_console = true, colorful_logs = false) ⇒ LoggerImplementation
constructor
A new instance of LoggerImplementation.
- #with_prefix(prefix) ⇒ Object
Constructor Details
#initialize(log_device, number_of_files = 10, max_file_size = 10 * 1024 * 1024, write_to_console = true, colorful_logs = false) ⇒ LoggerImplementation
Returns a new instance of LoggerImplementation.
169 170 171 172 173 174 175 |
# File 'lib/loops/logger.rb', line 169 def initialize(log_device, number_of_files = 10, max_file_size = 10 * 1024 * 1024, write_to_console = true, colorful_logs = false) super(log_device, number_of_files, max_file_size) self.formatter = Formatter.new(self) @write_to_console = write_to_console @colorful_logs = colorful_logs @prefix = nil end |
Instance Attribute Details
#colorful_logs ⇒ Object
Returns the value of attribute colorful_logs.
152 153 154 |
# File 'lib/loops/logger.rb', line 152 def colorful_logs @colorful_logs end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
150 151 152 |
# File 'lib/loops/logger.rb', line 150 def prefix @prefix end |
#write_to_console ⇒ Object
Returns the value of attribute write_to_console.
152 153 154 |
# File 'lib/loops/logger.rb', line 152 def write_to_console @write_to_console end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/loops/logger.rb', line 177 def add(severity, = nil, progname = nil, &block) begin if @colorful_logs = color_errors(severity, ) progname = color_errors(severity, progname) end super(severity, , progname, &block) if @write_to_console && ( || progname) puts self.formatter.call(%w(D I W E F A)[severity] || 'A', Time.now, progname, ) end rescue # ignore errors in logging end end |
#color_errors(severity, line) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/loops/logger.rb', line 203 def color_errors(severity, line) if severity < ::Logger::ERROR line else if line && line !~ /\e/ "\e[31m#{line}\e[0m" else line end end end |
#with_prefix(prefix) ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/loops/logger.rb', line 192 def with_prefix(prefix) raise "No block given" unless block_given? old_prefix = @prefix @prefix = prefix begin yield ensure @prefix = old_prefix end end |