Class: Console::Output::Serialized
- Inherits:
-
Object
- Object
- Console::Output::Serialized
- Defined in:
- lib/console/output/serialized.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
- #dump(record) ⇒ Object
-
#initialize(output, format: Format.default, **options) ⇒ Serialized
constructor
A new instance of Serialized.
Constructor Details
#initialize(output, format: Format.default, **options) ⇒ Serialized
Returns a new instance of Serialized.
13 14 15 16 |
# File 'lib/console/output/serialized.rb', line 13 def initialize(output, format: Format.default, **) @io = output @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
19 20 21 |
# File 'lib/console/output/serialized.rb', line 19 def format @format end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
18 19 20 |
# File 'lib/console/output/serialized.rb', line 18 def io @io end |
Instance Method Details
#call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
# File 'lib/console/output/serialized.rb', line 25 def call(subject = nil, *arguments, severity: UNKNOWN, **, &block) record = { time: Time.now.iso8601, severity: severity, oid: subject.object_id, pid: Process.pid, } # We want to log just a brief subject: if subject.is_a?(String) record[:subject] = subject elsif subject.is_a?(Module) record[:subject] = subject.name else record[:subject] = subject.class.name end if annotation = Fiber.current.annotation record[:annotation] = annotation end = arguments if block_given? if block.arity.zero? << yield else buffer = StringIO.new yield buffer << buffer.string end end if .size == 1 record[:message] = .first elsif .any? record[:message] = end record.update() @io.puts(self.dump(record)) end |
#dump(record) ⇒ Object
21 22 23 |
# File 'lib/console/output/serialized.rb', line 21 def dump(record) @format.dump(record) end |