Class: RubySmart::SimpleLogger::Formatter
- Inherits:
-
Object
- Object
- RubySmart::SimpleLogger::Formatter
- Defined in:
- lib/ruby_smart/simple_logger/formatter.rb
Constant Summary collapse
- SEVERITY_COLORS =
defines the severity colors
{ 'DEBUG' => :blue, 'INFO' => :cyan, 'WARN' => :yellow, 'ERROR' => :red, 'FATAL' => :bg_red, 'SUCCESS' => :green }
Class Method Summary collapse
-
.formats ⇒ Hash
returns all registered formats.
-
.formats=(formats) ⇒ Object
sets formats.
Instance Method Summary collapse
-
#call(severity, time, progname, data) ⇒ Object
standard call method - used to format provided params.
-
#clear! ⇒ Object
clears current formatter.
-
#formats ⇒ Hash
returns all class formats.
-
#initialize(opts = {}) ⇒ Formatter
constructor
initialize with options.
-
#opts(opts = nil) ⇒ Hash
combined getter & setter for options new options are merged with existing.
Constructor Details
#initialize(opts = {}) ⇒ Formatter
initialize with options
59 60 61 62 63 64 65 66 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 59 def initialize(opts = {}) # set default opts opts[:nl] = true if opts[:nl].nil? opts[:format] = :default if opts[:format].nil? # only store required options @opts = opts.slice(:nl, :format, :clr) end |
Class Method Details
.formats ⇒ Hash
returns all registered formats
9 10 11 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 9 def formats class_variable_get('@@formats') end |
.formats=(formats) ⇒ Object
sets formats
15 16 17 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 15 def formats=(formats) class_variable_set('@@formats', formats) end |
Instance Method Details
#call(severity, time, progname, data) ⇒ Object
standard call method - used to format provided params
69 70 71 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 69 def call(severity, time, progname, data) instance_exec(severity, time, progname, data, ¤t_formatter) end |
#clear! ⇒ Object
clears current formatter
101 102 103 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 101 def clear! @current_formatter = nil end |
#formats ⇒ Hash
returns all class formats
75 76 77 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 75 def formats self.class.formats end |
#opts(opts = nil) ⇒ Hash
combined getter & setter for options new options are merged with existing
92 93 94 95 96 97 98 |
# File 'lib/ruby_smart/simple_logger/formatter.rb', line 92 def opts(opts = nil) return @opts if opts.nil? clear! @opts.merge!(opts) end |