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, **options, &block) ⇒ Object
- #dump(record) ⇒ Object
-
#initialize(io = $stderr, format: JSON, verbose: false, **options) ⇒ Logger
constructor
A new instance of Logger.
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize(io = $stderr, format: JSON, verbose: false, **options) ⇒ Logger
Returns a new instance of Logger.
17 18 19 20 21 22 |
# File 'lib/console/serialized/logger.rb', line 17 def initialize(io = $stderr, format: JSON, verbose: false, **) @io = io @start = Time.now @format = format @verbose = verbose end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
26 27 28 |
# File 'lib/console/serialized/logger.rb', line 26 def format @format end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
24 25 26 |
# File 'lib/console/serialized/logger.rb', line 24 def io @io end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
25 26 27 |
# File 'lib/console/serialized/logger.rb', line 25 def start @start end |
Instance Method Details
#call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/console/serialized/logger.rb', line 36 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 if exception = find_exception() record[:error] = { kind: exception.class, message: exception., stack: format_stack(exception) } end record.update() @io.puts(self.dump(record)) end |
#dump(record) ⇒ Object
32 33 34 |
# File 'lib/console/serialized/logger.rb', line 32 def dump(record) @format.dump(record) end |
#verbose!(value = true) ⇒ Object
28 29 30 |
# File 'lib/console/serialized/logger.rb', line 28 def verbose!(value = true) @verbose = true end |