Class: TelemetryLogSink
- Inherits:
-
Logger::LogDevice
- Object
- Logger::LogDevice
- TelemetryLogSink
- Defined in:
- lib/aws_lambda_ric/telemetry_log_sink.rb
Constant Summary collapse
- FRAME_BYTES =
[0xa55a0001].pack('L>')
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(file:) ⇒ TelemetryLogSink
constructor
TelemetryLogSink implements the logging contract between runtimes and the platform.
- #reopen(log = nil) ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(file:) ⇒ TelemetryLogSink
TelemetryLogSink implements the logging contract between runtimes and the platform. It implements a simple framing protocol so message boundaries can be determined. Each frame can be visualized as follows:
----------------------
————————-----------------------
| Frame Type - 4 bytes | Length (len) - 4 bytes | Message - 'len' bytes | ----------------------
————————-----------------------
The first 4 bytes indicate the type of the frame - log frames have a type defined as the hex value 0xa55a0001. The second 4 bytes should indicate the message's length. The next 'len' bytes contain the message. The byte order is big-endian.
20 21 22 |
# File 'lib/aws_lambda_ric/telemetry_log_sink.rb', line 20 def initialize(file:) @file = file end |
Instance Method Details
#close ⇒ Object
40 41 42 |
# File 'lib/aws_lambda_ric/telemetry_log_sink.rb', line 40 def close # do nothing end |
#reopen(log = nil) ⇒ Object
36 37 38 |
# File 'lib/aws_lambda_ric/telemetry_log_sink.rb', line 36 def reopen(log = nil) # do nothing end |
#write(msg) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/aws_lambda_ric/telemetry_log_sink.rb', line 26 def write(msg) if @file.nil? || @file.closed? $stdout.write(msg) else @file.write(FRAME_BYTES) @file.write([msg.bytesize].pack('L>')) @file.write(msg) end end |