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.
32 33 34 35 36 37 |
# File 'lib/console/serialized/logger.rb', line 32 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.
41 42 43 |
# File 'lib/console/serialized/logger.rb', line 41 def format @format end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
39 40 41 |
# File 'lib/console/serialized/logger.rb', line 39 def io @io end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
40 41 42 |
# File 'lib/console/serialized/logger.rb', line 40 def start @start end |
Instance Method Details
#call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
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 87 88 89 90 91 92 93 |
# File 'lib/console/serialized/logger.rb', line 51 def call(subject = nil, *arguments, severity: UNKNOWN, **, &block) record = { time: Time.now.iso8601, severity: severity, class: subject.class, oid: subject.object_id, pid: Process.pid, } if subject record[:subject] = subject 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
47 48 49 |
# File 'lib/console/serialized/logger.rb', line 47 def dump(record) @format.dump(record) end |
#verbose!(value = true) ⇒ Object
43 44 45 |
# File 'lib/console/serialized/logger.rb', line 43 def verbose!(value = true) @verbose = true end |