Class: Better::Logger::Config
- Inherits:
-
Object
- Object
- Better::Logger::Config
- Defined in:
- lib/better-logger/config.rb
Instance Attribute Summary collapse
- #color ⇒ Object
-
#datetime_format ⇒ Object
writeonly
Sets the attribute datetime_format.
- #formatter ⇒ Object
- #log_level ⇒ Object
- #time_format ⇒ Object
Instance Method Summary collapse
- #color? ⇒ Boolean
- #error_to ⇒ Object
- #error_to=(new_error_to) ⇒ Object
- #log_to ⇒ Object
- #log_to=(new_log_to) ⇒ Object
Instance Attribute Details
#color ⇒ Object
6 7 8 9 |
# File 'lib/better-logger/config.rb', line 6 def color @color = true if @color.nil? @color end |
#datetime_format=(value) ⇒ Object (writeonly)
Sets the attribute datetime_format
4 5 6 |
# File 'lib/better-logger/config.rb', line 4 def datetime_format=(value) @datetime_format = value end |
#formatter ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/better-logger/config.rb', line 47 def formatter @formatter ||= lambda do |, level| _level = level.to_s.ljust(5) _time = Time.now.strftime(config.time_format) if config.color? case level when :debug _level = _level.magenta when :info _level = _level.cyan when :warn _level = _level.yellow when :error _level = _level.red when :fatal _level = _level.red end end file_location = caller[4].sub(Dir.pwd + '/', '') "[#{_time}][#{_level}][#{file_location}] #{}" end end |
#log_level ⇒ Object
39 40 41 |
# File 'lib/better-logger/config.rb', line 39 def log_level @log_level ||= :info end |
#time_format ⇒ Object
43 44 45 |
# File 'lib/better-logger/config.rb', line 43 def time_format @time_format ||= "%Y/%m/%d %H:%M:%S.%L" end |
Instance Method Details
#color? ⇒ Boolean
11 12 13 |
# File 'lib/better-logger/config.rb', line 11 def color? color end |
#error_to ⇒ Object
27 28 29 |
# File 'lib/better-logger/config.rb', line 27 def error_to @error_to ||= STDERR end |
#error_to=(new_error_to) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/better-logger/config.rb', line 31 def error_to= new_error_to if new_error_to.is_a? String @error_to = File.open(new_error_to, 'a') else @error_to = new_error_to end end |
#log_to ⇒ Object
15 16 17 |
# File 'lib/better-logger/config.rb', line 15 def log_to @log_to ||= STDOUT end |
#log_to=(new_log_to) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/better-logger/config.rb', line 19 def log_to= new_log_to if new_log_to.is_a? String @log_to = File.open(new_log_to, 'a') else @log_to = new_log_to end end |