Class: TestData::Log
- Inherits:
-
Object
- Object
- TestData::Log
- Defined in:
- lib/test_data/log.rb
Constant Summary collapse
- LEVELS =
[:debug, :info, :warn, :error, :quiet]
- DEFAULT_WRITER =
->(, level) do output = "[test_data:#{level}] #{}" if [:warn, :error].include?(level) warn output else puts output end end
- PLAIN_WRITER =
->(, level) do if [:warn, :error].include?(level) warn else puts end end
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #reset ⇒ Object
- #with_plain_writer(&blk) ⇒ Object
- #with_writer(writer, &blk) ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
26 27 28 |
# File 'lib/test_data/log.rb', line 26 def initialize reset end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
24 25 26 |
# File 'lib/test_data/log.rb', line 24 def level @level end |
#writer ⇒ Object
Returns the value of attribute writer.
24 25 26 |
# File 'lib/test_data/log.rb', line 24 def writer @writer end |
Instance Method Details
#reset ⇒ Object
38 39 40 41 |
# File 'lib/test_data/log.rb', line 38 def reset self.level = ENV["TEST_DATA_LOG_LEVEL"]&.to_sym || :info @writer = DEFAULT_WRITER end |
#with_plain_writer(&blk) ⇒ Object
66 67 68 |
# File 'lib/test_data/log.rb', line 66 def with_plain_writer(&blk) with_writer(PLAIN_WRITER, &blk) end |
#with_writer(writer, &blk) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/test_data/log.rb', line 59 def with_writer(writer, &blk) og_writer = self.writer self.writer = writer blk.call self.writer = og_writer end |