Class: LibSL::Logger
- Inherits:
-
Object
- Object
- LibSL::Logger
- Defined in:
- lib/logging.rb
Constant Summary collapse
- RESET_COLOR =
Colors
"\e[0m"- ERROR_COLOR =
Reset
"\e[1m\e[31m"- DEBUG_COLOR =
Red
"\e[1m\e[37m"- INFO_COLOR =
Grey
"\e[1m\e[33m"- UNDERLINE =
Yellow
"\e[4m"
Instance Method Summary collapse
- #debug(message, *args) ⇒ Object
- #error(message, *args) ⇒ Object
- #info(message, *args) ⇒ Object
-
#initialize(output = nil, debug = false, colors = true) ⇒ Logger
constructor
Underline.
- #log(level, message, *args) ⇒ Object
Constructor Details
#initialize(output = nil, debug = false, colors = true) ⇒ Logger
Underline
27 28 29 30 31 |
# File 'lib/logging.rb', line 27 def initialize(output=nil, debug=false, colors=true) @output = output.is_a?(LogFile) ? output : LogFile.new(output) @debug = debug @colors = colors end |
Instance Method Details
#debug(message, *args) ⇒ Object
39 40 41 42 |
# File 'lib/logging.rb', line 39 def debug(, *args) return unless @debug log(:debug, , *args) end |
#error(message, *args) ⇒ Object
48 49 50 |
# File 'lib/logging.rb', line 48 def error(, *args) log(:error, , *args) end |
#info(message, *args) ⇒ Object
44 45 46 |
# File 'lib/logging.rb', line 44 def info(, *args) log(:info, , *args) end |
#log(level, message, *args) ⇒ Object
33 34 35 36 37 |
# File 'lib/logging.rb', line 33 def log(level, , *args) color = self.class.const_get("#{level.to_s.upcase}_COLOR".to_sym) @output << "[" << apply_color(color + UNDERLINE, level.to_s.upcase + " " + Time.now.strftime("%F %T")) << "] " \ << sprintf(apply_color(color, ), *args) << "\n" end |