Class: Console::Serialized::Logger
- Inherits:
-
Object
- Object
- Console::Serialized::Logger
- Defined in:
- lib/console/serialized/logger.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #call(subject = nil, *arguments, severity: UNKNOWN, &block) ⇒ Object
-
#initialize(io = $stderr, format: JSON) ⇒ Logger
constructor
A new instance of Logger.
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize(io = $stderr, format: JSON) ⇒ Logger
Returns a new instance of Logger.
30 31 32 33 34 |
# File 'lib/console/serialized/logger.rb', line 30 def initialize(io = $stderr, format: JSON) @io = io @start = Time.now @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
38 39 40 |
# File 'lib/console/serialized/logger.rb', line 38 def format @format end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
36 37 38 |
# File 'lib/console/serialized/logger.rb', line 36 def io @io end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
37 38 39 |
# File 'lib/console/serialized/logger.rb', line 37 def start @start end |
Instance Method Details
#call(subject = nil, *arguments, severity: UNKNOWN, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/console/serialized/logger.rb', line 43 def call(subject = nil, *arguments, severity: UNKNOWN, &block) = { time: Time.now.iso8601, severity: severity, } if subject [:subject] = subject end if arguments.any? [:arguments] = arguments end if block_given? if block.arity.zero? [:message] = yield else buffer = StringIO.new yield buffer [:message] = buffer.string end end @io.puts(@format.dump()) end |
#verbose!(value = true) ⇒ Object
40 41 |
# File 'lib/console/serialized/logger.rb', line 40 def verbose!(value = true) end |